pshenmic-dpp 1.0.5 → 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 (118) hide show
  1. package/.github/workflows/build.yml +1 -1
  2. package/.github/workflows/publish.yml +1 -1
  3. package/Cargo.lock +147 -49
  4. package/Cargo.toml +13 -7
  5. package/README.md +10 -1
  6. package/dist/wasm/index.d.ts +52 -0
  7. package/dist/wasm/pshenmic_dpp.d.ts +962 -0
  8. package/dist/wasm/pshenmic_dpp.js +3342 -875
  9. package/dist/wasm/pshenmic_dpp_bg.js +1 -1
  10. package/dist/wasm/pshenmic_dpp_bg.wasm.d.ts +440 -0
  11. package/docs/AssetLockProof.md +107 -0
  12. package/docs/Building.md +50 -0
  13. package/docs/ChainLockProof.md +63 -0
  14. package/docs/CoreScript.md +17 -0
  15. package/docs/DataContract.md +192 -0
  16. package/docs/DataContractCreateTransition.md +84 -0
  17. package/docs/DataContractUpdateTransition.md +84 -0
  18. package/docs/Document.md +396 -0
  19. package/docs/DocumentBaseTransition.md +111 -0
  20. package/docs/DocumentCreateTransition.md +132 -0
  21. package/docs/DocumentDeleteTransition.md +82 -0
  22. package/docs/DocumentPurchaseTransition.md +109 -0
  23. package/docs/DocumentReplaceTransition.md +112 -0
  24. package/docs/DocumentTransferTransition.md +96 -0
  25. package/docs/DocumentTransition.md +125 -0
  26. package/docs/DocumentUpdatePriceTransition.md +109 -0
  27. package/docs/DocumentsBatch.md +133 -0
  28. package/docs/Enums.md +103 -0
  29. package/docs/Home.md +28 -0
  30. package/docs/Identifier.md +37 -0
  31. package/docs/Identity.md +140 -0
  32. package/docs/IdentityCreateTransition.md +155 -0
  33. package/docs/IdentityCreditTransfer.md +187 -0
  34. package/docs/IdentityCreditWithdrawalTransition.md +244 -0
  35. package/docs/IdentityPublicKey.md +348 -0
  36. package/docs/IdentityPublicKeyInCreation.md +141 -0
  37. package/docs/IdentityTopUpTransition.md +166 -0
  38. package/docs/IdentityUpdateTransition.md +234 -0
  39. package/docs/InstantAssetLockProof.md +117 -0
  40. package/docs/InstantLock.md +100 -0
  41. package/docs/OutPoint.md +80 -0
  42. package/docs/PrefundedVotingBalance.md +48 -0
  43. package/docs/PrivateKey.md +112 -0
  44. package/docs/TxOut.md +93 -0
  45. package/package.json +3 -3
  46. package/packages/asset_lock_proof/Cargo.toml +19 -0
  47. package/packages/asset_lock_proof/src/chain/mod.rs +79 -0
  48. package/packages/asset_lock_proof/src/instant/instant_lock.rs +111 -0
  49. package/packages/asset_lock_proof/src/instant/mod.rs +115 -0
  50. package/packages/asset_lock_proof/src/lib.rs +133 -0
  51. package/packages/asset_lock_proof/src/outpoint/mod.rs +79 -0
  52. package/packages/asset_lock_proof/src/tx_out/mod.rs +80 -0
  53. package/packages/cbor_conversation/Cargo.toml +1 -1
  54. package/packages/core_script/Cargo.toml +13 -0
  55. package/packages/core_script/src/lib.rs +69 -0
  56. package/packages/data_contract/Cargo.toml +2 -1
  57. package/packages/data_contract/src/lib.rs +34 -30
  58. package/packages/data_contract_transitions/Cargo.toml +1 -1
  59. package/packages/data_contract_transitions/src/create/mod.rs +3 -3
  60. package/packages/data_contract_transitions/src/update/mod.rs +3 -3
  61. package/packages/document/Cargo.toml +2 -1
  62. package/packages/document/src/lib.rs +13 -12
  63. package/packages/document/src/methods/mod.rs +41 -38
  64. package/packages/documents_batch/Cargo.toml +2 -1
  65. package/packages/documents_batch/src/document_base_transition/mod.rs +16 -20
  66. package/packages/documents_batch/src/document_transition/mod.rs +9 -9
  67. package/packages/documents_batch/src/lib.rs +23 -16
  68. package/packages/documents_batch/src/transitions/create/mod.rs +5 -2
  69. package/packages/documents_batch/src/transitions/transfer/mod.rs +9 -11
  70. package/packages/enums/Cargo.toml +1 -1
  71. package/packages/enums/src/batch/batch_enum.rs +2 -2
  72. package/packages/enums/src/lib.rs +2 -0
  73. package/packages/enums/src/lock_types/mod.rs +65 -0
  74. package/packages/enums/src/platform/mod.rs +2 -0
  75. package/packages/enums/src/withdrawal/mod.rs +72 -0
  76. package/packages/identifier/Cargo.toml +9 -0
  77. package/packages/identifier/src/lib.rs +105 -0
  78. package/packages/identity/Cargo.toml +2 -1
  79. package/packages/identity/src/lib.rs +13 -18
  80. package/packages/identity_public_key/Cargo.toml +1 -1
  81. package/packages/identity_transitions/Cargo.toml +7 -3
  82. package/packages/identity_transitions/src/create_transition/mod.rs +99 -36
  83. package/packages/identity_transitions/src/credit_withdrawal_transition/mod.rs +212 -0
  84. package/packages/identity_transitions/src/identity_credit_transfer_transition/mod.rs +169 -0
  85. package/packages/identity_transitions/src/lib.rs +6 -1
  86. package/packages/identity_transitions/src/{create_transition/public_key_in_creation → public_key_in_creation}/mod.rs +67 -20
  87. package/packages/identity_transitions/src/top_up_transition/mod.rs +141 -0
  88. package/packages/identity_transitions/src/update_transition/mod.rs +213 -0
  89. package/packages/private_key/Cargo.toml +1 -1
  90. package/packages/state_transition/Cargo.toml +2 -1
  91. package/packages/state_transition/src/lib.rs +3 -2
  92. package/packages/utils/Cargo.toml +2 -2
  93. package/packages/utils/src/lib.rs +0 -3
  94. package/scripts/build-js.sh +16 -0
  95. package/scripts/build.sh +5 -1
  96. package/src/lib.rs +1 -0
  97. package/tests/AssetLockProof.spec.js +80 -0
  98. package/tests/ChainLockProof.spec.js +69 -0
  99. package/tests/CoreScript.spec.js +37 -0
  100. package/tests/DataContract.spec.js +17 -14
  101. package/tests/Document.spec.js +14 -8
  102. package/tests/DocumentBatchTransition.spec.js +11 -11
  103. package/tests/DocumentTransition.spec.js +4 -4
  104. package/tests/DocumentsTransitions.spec.js +22 -22
  105. package/tests/Identifier.spec.js +84 -0
  106. package/tests/Identity.spec.js +1 -1
  107. package/tests/IdentityCreateTransition.spec.js +93 -0
  108. package/tests/IdentityCreditTransferTransition.spec.js +146 -0
  109. package/tests/IdentityCreditWithdrawalTransition.spec.js +192 -0
  110. package/tests/IdentityTopUpTransition.spec.js +131 -0
  111. package/tests/IdentityUpdateTransition.spec.js +147 -0
  112. package/tests/InstantLockProof.spec.js +97 -0
  113. package/tests/OutPoint.spec.js +55 -0
  114. package/tests/PublicKeyInCreation.spec.js +258 -0
  115. package/tests/TxOut.spec.js +76 -0
  116. package/tests/mocks/Locks/index.js +5 -0
  117. package/tests/mocks/PublicKey/index.js +1 -1
  118. package/typings/index.d.ts +52 -0
@@ -0,0 +1,133 @@
1
+ pub mod chain;
2
+ pub mod instant;
3
+ pub mod outpoint;
4
+ mod tx_out;
5
+
6
+ use crate::chain::ChainAssetLockProofWASM;
7
+ use crate::instant::InstantAssetLockProofWASM;
8
+ use dpp::identity::state_transition::asset_lock_proof::InstantAssetLockProof;
9
+
10
+ use crate::outpoint::OutPointWASM;
11
+ use dpp::prelude::AssetLockProof;
12
+ use pshenmic_dpp_enums::lock_types::AssetLockProofTypeWASM;
13
+ use pshenmic_dpp_utils::WithJsError;
14
+ use serde::Serialize;
15
+ use wasm_bindgen::JsValue;
16
+ use wasm_bindgen::prelude::wasm_bindgen;
17
+
18
+ #[wasm_bindgen(js_name = "AssetLockProofWASM")]
19
+ #[derive(Clone)]
20
+ pub struct AssetLockProofWASM(AssetLockProof);
21
+
22
+ impl From<AssetLockProofWASM> for AssetLockProof {
23
+ fn from(proof: AssetLockProofWASM) -> Self {
24
+ proof.0
25
+ }
26
+ }
27
+
28
+ impl From<AssetLockProof> for AssetLockProofWASM {
29
+ fn from(proof: AssetLockProof) -> Self {
30
+ AssetLockProofWASM(proof)
31
+ }
32
+ }
33
+
34
+ impl From<ChainAssetLockProofWASM> for AssetLockProofWASM {
35
+ fn from(proof: ChainAssetLockProofWASM) -> Self {
36
+ AssetLockProofWASM(AssetLockProof::Chain(proof.into()))
37
+ }
38
+ }
39
+
40
+ impl From<InstantAssetLockProofWASM> for AssetLockProofWASM {
41
+ fn from(proof: InstantAssetLockProofWASM) -> Self {
42
+ AssetLockProofWASM(AssetLockProof::Instant(proof.into()))
43
+ }
44
+ }
45
+
46
+ impl From<AssetLockProof> for ChainAssetLockProofWASM {
47
+ fn from(proof: AssetLockProof) -> ChainAssetLockProofWASM {
48
+ match proof {
49
+ AssetLockProof::Chain(chain) => ChainAssetLockProofWASM::from(chain),
50
+ _ => panic!("invalid asset lock proof. must contains chain lock"),
51
+ }
52
+ }
53
+ }
54
+
55
+ impl From<AssetLockProof> for InstantAssetLockProofWASM {
56
+ fn from(proof: AssetLockProof) -> InstantAssetLockProofWASM {
57
+ match proof {
58
+ AssetLockProof::Instant(instant) => InstantAssetLockProofWASM::from(instant),
59
+ _ => panic!("invalid asset lock proof. must contains chain lock"),
60
+ }
61
+ }
62
+ }
63
+
64
+ #[wasm_bindgen]
65
+ impl AssetLockProofWASM {
66
+ #[wasm_bindgen(constructor)]
67
+ pub fn new(js_asset_lock_proof_type: JsValue) -> Result<AssetLockProofWASM, JsValue> {
68
+ let asset_lock_proof_type = AssetLockProofTypeWASM::try_from(js_asset_lock_proof_type)?;
69
+
70
+ match asset_lock_proof_type {
71
+ AssetLockProofTypeWASM::Chain => Err(JsValue::from_str(&"ChainLock unavailable")),
72
+ AssetLockProofTypeWASM::Instant => {
73
+ Ok(InstantAssetLockProofWASM::from(InstantAssetLockProof::default()).into())
74
+ }
75
+ }
76
+ }
77
+
78
+ #[wasm_bindgen(js_name = "createInstantAssetLockProof")]
79
+ pub fn new_instant_asset_lock_proof(
80
+ instant_lock: Vec<u8>,
81
+ transaction: Vec<u8>,
82
+ output_index: u32,
83
+ ) -> Result<AssetLockProofWASM, JsValue> {
84
+ Ok(InstantAssetLockProofWASM::new(instant_lock, transaction, output_index)?.into())
85
+ }
86
+
87
+ #[wasm_bindgen(js_name = "createChainAssetLockProof")]
88
+ pub fn new_chain_asset_lock_proof(
89
+ core_chain_locked_height: u32,
90
+ out_point: &OutPointWASM,
91
+ ) -> Result<AssetLockProofWASM, JsValue> {
92
+ Ok(ChainAssetLockProofWASM::new(core_chain_locked_height, out_point)?.into())
93
+ }
94
+
95
+ // #[wasm_bindgen(js_name = "fromRawObject")]
96
+ // pub fn from_raw_object(raw_asset_lock_proof: JsValue) -> Result<AssetLockProofWASM, JsValue> {
97
+ // let lock_type = get_type_from_raw_asset_lock_proof(&raw_asset_lock_proof)?;
98
+ //
99
+ // match lock_type {
100
+ // AssetLockProofTypeWASM::Instant => {
101
+ // Ok(InstantAssetLockProofWASM::from_raw_value(raw_asset_lock_proof)?.into())
102
+ // }
103
+ // AssetLockProofTypeWASM::Chain => {
104
+ // Ok(ChainAssetLockProofWASM::from_raw_value(raw_asset_lock_proof)?.into())
105
+ // }
106
+ // }
107
+ // }
108
+
109
+ #[wasm_bindgen(js_name = "getLockType")]
110
+ pub fn get_lock_type(&self) -> String {
111
+ match self.0 {
112
+ AssetLockProof::Chain(_) => AssetLockProofTypeWASM::Chain.into(),
113
+ AssetLockProof::Instant(_) => AssetLockProofTypeWASM::Instant.into(),
114
+ }
115
+ }
116
+
117
+ #[wasm_bindgen(js_name = "getInstantLockProof")]
118
+ pub fn get_instant_lock(&self) -> InstantAssetLockProofWASM {
119
+ self.clone().0.into()
120
+ }
121
+
122
+ #[wasm_bindgen(js_name = "getChainLockProof")]
123
+ pub fn get_chain_lock(&self) -> ChainAssetLockProofWASM {
124
+ self.clone().0.into()
125
+ }
126
+
127
+ #[wasm_bindgen(js_name = "toObject")]
128
+ pub fn to_object(&self) -> Result<JsValue, JsValue> {
129
+ let json_value = self.0.to_raw_object().with_js_error()?;
130
+
131
+ Ok(json_value.serialize(&serde_wasm_bindgen::Serializer::json_compatible())?)
132
+ }
133
+ }
@@ -0,0 +1,79 @@
1
+ use dpp::dashcore::{OutPoint, Txid};
2
+ use pshenmic_dpp_utils::IntoWasm;
3
+ use wasm_bindgen::JsValue;
4
+ use wasm_bindgen::prelude::wasm_bindgen;
5
+
6
+ #[wasm_bindgen(js_name = "OutPointWASM")]
7
+ #[derive(Clone)]
8
+ pub struct OutPointWASM(OutPoint);
9
+
10
+ impl From<OutPoint> for OutPointWASM {
11
+ fn from(outpoint: OutPoint) -> Self {
12
+ OutPointWASM(outpoint)
13
+ }
14
+ }
15
+
16
+ impl From<OutPointWASM> for OutPoint {
17
+ fn from(outpoint: OutPointWASM) -> Self {
18
+ outpoint.0
19
+ }
20
+ }
21
+
22
+ impl TryFrom<JsValue> for OutPointWASM {
23
+ type Error = JsValue;
24
+ fn try_from(value: JsValue) -> Result<Self, Self::Error> {
25
+ let value = value.to_wasm::<OutPointWASM>("OutPointWASM")?;
26
+
27
+ Ok(value.clone())
28
+ }
29
+ }
30
+
31
+ #[wasm_bindgen]
32
+ impl OutPointWASM {
33
+ #[wasm_bindgen(constructor)]
34
+ pub fn new(txid_hex: String, vout: u32) -> Result<OutPointWASM, JsValue> {
35
+ let out_point = Txid::from_hex(&txid_hex).map_err(|err| JsValue::from(err.to_string()))?;
36
+
37
+ Ok(OutPointWASM(OutPoint {
38
+ txid: out_point,
39
+ vout,
40
+ }))
41
+ }
42
+
43
+ #[wasm_bindgen(js_name = "getVOUT")]
44
+ pub fn get_vout(&self) -> u32 {
45
+ self.0.vout
46
+ }
47
+
48
+ #[wasm_bindgen(js_name = "getTXID")]
49
+ pub fn get_tx_id(&self) -> String {
50
+ self.0.txid.to_hex()
51
+ }
52
+
53
+ #[wasm_bindgen(js_name = "toBytes")]
54
+ pub fn to_bytes(&self) -> Vec<u8> {
55
+ let slice: [u8; 36] = self.0.into();
56
+ slice.to_vec()
57
+ }
58
+
59
+ #[wasm_bindgen(js_name = "fromBytes")]
60
+ pub fn from_buffer(js_buffer: Vec<u8>) -> OutPointWASM {
61
+ let mut buffer = [0u8; 36];
62
+ let bytes = js_buffer.as_slice();
63
+ let len = bytes.len();
64
+ buffer[..len].copy_from_slice(bytes);
65
+
66
+ OutPointWASM(OutPoint::from(buffer))
67
+ }
68
+ }
69
+
70
+ impl OutPointWASM {
71
+ pub fn vec_from_js_value(js_outpoints: &js_sys::Array) -> Result<Vec<OutPointWASM>, JsValue> {
72
+ let outpoints: Vec<OutPointWASM> = js_outpoints
73
+ .iter()
74
+ .map(|key| OutPointWASM::try_from(key))
75
+ .collect::<Result<Vec<OutPointWASM>, JsValue>>()?;
76
+
77
+ Ok(outpoints)
78
+ }
79
+ }
@@ -0,0 +1,80 @@
1
+ use dpp::dashcore::{ScriptBuf, TxOut};
2
+ use js_sys::Uint8Array;
3
+ use wasm_bindgen::JsValue;
4
+ use wasm_bindgen::prelude::wasm_bindgen;
5
+
6
+ #[wasm_bindgen(js_name = "TxOutWASM")]
7
+ #[derive(Clone)]
8
+ pub struct TxOutWASM(TxOut);
9
+
10
+ impl From<TxOut> for TxOutWASM {
11
+ fn from(value: TxOut) -> Self {
12
+ TxOutWASM(value)
13
+ }
14
+ }
15
+
16
+ impl From<TxOutWASM> for TxOut {
17
+ fn from(value: TxOutWASM) -> Self {
18
+ value.0
19
+ }
20
+ }
21
+
22
+ #[wasm_bindgen]
23
+ impl TxOutWASM {
24
+ #[wasm_bindgen(constructor)]
25
+ pub fn new(value: u64, script_pubkey: JsValue) -> Result<TxOutWASM, JsValue> {
26
+ let tx_out: Result<TxOut, JsValue> = match script_pubkey.is_array() {
27
+ true => Ok(TxOut {
28
+ value,
29
+ script_pubkey: ScriptBuf::from_bytes(Uint8Array::from(script_pubkey).to_vec()),
30
+ }),
31
+ false => match script_pubkey.is_string() {
32
+ true => Ok(TxOut {
33
+ value,
34
+ script_pubkey: ScriptBuf::from_hex(&script_pubkey.as_string().unwrap())
35
+ .map_err(|err| JsValue::from(err.to_string()))?,
36
+ }),
37
+ false => Err(JsValue::from("Invalid script pubkey")),
38
+ },
39
+ };
40
+
41
+ Ok(TxOutWASM(tx_out?))
42
+ }
43
+
44
+ #[wasm_bindgen(getter = "value")]
45
+ pub fn get_value(&self) -> u64 {
46
+ self.0.value
47
+ }
48
+
49
+ #[wasm_bindgen(getter = "scriptPubKeyHex")]
50
+ pub fn get_script_pubkey_hex(&self) -> String {
51
+ self.0.script_pubkey.to_hex_string()
52
+ }
53
+
54
+ #[wasm_bindgen(getter = "scriptPubKeyBytes")]
55
+ pub fn get_script_pubkey_bytes(&self) -> Vec<u8> {
56
+ self.0.script_pubkey.to_bytes()
57
+ }
58
+
59
+ #[wasm_bindgen(setter = "value")]
60
+ pub fn set_value(&mut self, value: u64) {
61
+ self.0.value = value;
62
+ }
63
+
64
+ #[wasm_bindgen(setter = "scriptPubKeyHex")]
65
+ pub fn set_script_pubkey_hex(&mut self, script_pubkey_hex: String) -> Result<(), JsValue> {
66
+ self.0.script_pubkey = ScriptBuf::from_hex(&script_pubkey_hex)
67
+ .map_err(|err| JsValue::from(err.to_string()))?;
68
+ Ok(())
69
+ }
70
+
71
+ #[wasm_bindgen(setter = "scriptPubKeyBytes")]
72
+ pub fn set_script_pubkey_bytes(&mut self, script_pubkey_bytes: Vec<u8>) {
73
+ self.0.script_pubkey = ScriptBuf::from_bytes(script_pubkey_bytes);
74
+ }
75
+
76
+ #[wasm_bindgen(js_name = "getScriptPubKeyASM")]
77
+ pub fn get_script_pubkey_asm(&self) -> String {
78
+ self.0.script_pubkey.to_asm_string()
79
+ }
80
+ }
@@ -7,7 +7,7 @@ edition = "2024"
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
  "cbor",
13
13
  ]}
@@ -0,0 +1,13 @@
1
+ [package]
2
+ name = "pshenmic_dpp_core_script"
3
+ edition = "2024"
4
+ version.workspace = true
5
+
6
+ [lib]
7
+ crate-type = ["cdylib", "lib"]
8
+
9
+ [dependencies]
10
+ wasm-bindgen = { version = "=0.2.100", default-features = false, features = ["serde-serialize"] }
11
+ dpp = { git = "https://github.com/dashpay/platform", branch = "master", default-features = false, features = [
12
+ "state-transition-signing"
13
+ ]}
@@ -0,0 +1,69 @@
1
+ use dpp::dashcore::opcodes;
2
+ use dpp::identity::core_script::CoreScript;
3
+ use dpp::platform_value::string_encoding::Encoding::Base64;
4
+ use wasm_bindgen::prelude::wasm_bindgen;
5
+
6
+ #[wasm_bindgen(js_name = "CoreScriptWASM")]
7
+ #[derive(Clone)]
8
+ pub struct CoreScriptWASM(CoreScript);
9
+
10
+ impl From<CoreScriptWASM> for CoreScript {
11
+ fn from(value: CoreScriptWASM) -> Self {
12
+ value.0
13
+ }
14
+ }
15
+
16
+ impl From<CoreScript> for CoreScriptWASM {
17
+ fn from(value: CoreScript) -> Self {
18
+ CoreScriptWASM(value)
19
+ }
20
+ }
21
+
22
+ #[wasm_bindgen]
23
+ impl CoreScriptWASM {
24
+ #[wasm_bindgen(js_name = "fromBytes")]
25
+ pub fn from_bytes(bytes: Vec<u8>) -> Self {
26
+ CoreScriptWASM(CoreScript::from_bytes(bytes))
27
+ }
28
+
29
+ #[wasm_bindgen(js_name = "newP2PKH")]
30
+ pub fn new_p2pkh(js_key_hash: Vec<u8>) -> Self {
31
+ let mut key_hash = [0u8; 20];
32
+ let bytes = js_key_hash.as_slice();
33
+ let len = bytes.len().min(32);
34
+ key_hash[..len].copy_from_slice(&bytes[..len]);
35
+
36
+ CoreScriptWASM(CoreScript::new_p2pkh(key_hash))
37
+ }
38
+
39
+ #[wasm_bindgen(js_name = "newP2SH")]
40
+ pub fn new_p2sh(js_script_hash: Vec<u8>) -> Self {
41
+ let mut script_hash = [0u8; 20];
42
+ let bytes = js_script_hash.as_slice();
43
+ let len = bytes.len().min(32);
44
+ script_hash[..len].copy_from_slice(&bytes[..len]);
45
+
46
+ let mut bytes = vec![
47
+ opcodes::all::OP_HASH160.to_u8(),
48
+ opcodes::all::OP_PUSHBYTES_20.to_u8(),
49
+ ];
50
+ bytes.extend_from_slice(&script_hash);
51
+ bytes.push(opcodes::all::OP_EQUAL.to_u8());
52
+ Self::from_bytes(bytes)
53
+ }
54
+
55
+ #[wasm_bindgen(js_name = "toString")]
56
+ pub fn to_string(&self) -> String {
57
+ self.0.to_string(Base64)
58
+ }
59
+
60
+ #[wasm_bindgen(js_name = "toBytes")]
61
+ pub fn to_bytes(&self) -> Vec<u8> {
62
+ self.0.to_bytes()
63
+ }
64
+
65
+ #[wasm_bindgen(js_name = "toASMString")]
66
+ pub fn to_asm_string(&self) -> String {
67
+ self.0.to_asm_string()
68
+ }
69
+ }
@@ -7,9 +7,10 @@ edition = "2024"
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
  pshenmic_dpp_utils = {path = "../utils"}
12
12
  pshenmic_dpp_enums = {path = "../enums"}
13
+ pshenmic_dpp_identifier = { path = "../identifier" }
13
14
  dpp = { git = "https://github.com/dashpay/platform", branch = "master", default-features = false, features = [
14
15
  "data-contract-json-conversion",
15
16
  ]}
@@ -16,7 +16,8 @@ use dpp::serialization::{
16
16
  };
17
17
  use dpp::version::PlatformVersion;
18
18
  use pshenmic_dpp_enums::platform::PlatformVersionWASM;
19
- use pshenmic_dpp_utils::{ToSerdeJSONExt, WithJsError, identifier_from_js_value};
19
+ use pshenmic_dpp_identifier::IdentifierWASM;
20
+ use pshenmic_dpp_utils::{ToSerdeJSONExt, WithJsError};
20
21
  use std::collections::BTreeMap;
21
22
  use wasm_bindgen::JsValue;
22
23
  use wasm_bindgen::prelude::wasm_bindgen;
@@ -41,7 +42,7 @@ impl From<DataContractWASM> for DataContract {
41
42
  impl DataContractWASM {
42
43
  #[wasm_bindgen(constructor)]
43
44
  pub fn from_js_values(
44
- js_owner_id: JsValue,
45
+ js_owner_id: &JsValue,
45
46
  identity_nonce: IdentityNonce,
46
47
  js_schema: JsValue,
47
48
  js_definitions: Option<js_sys::Object>,
@@ -50,14 +51,14 @@ impl DataContractWASM {
50
51
  ) -> Result<DataContractWASM, JsValue> {
51
52
  let serializer = serde_wasm_bindgen::Serializer::json_compatible();
52
53
 
53
- let owner_id = identifier_from_js_value(&js_owner_id)?;
54
+ let owner_id: IdentifierWASM = js_owner_id.clone().try_into()?;
54
55
 
55
- let owner_id_value = Value::from(owner_id.to_string(Base58));
56
+ let owner_id_value = Value::from(owner_id.get_base58());
56
57
 
57
58
  let schema: Value = serde_wasm_bindgen::from_value(js_schema)?;
58
59
 
59
60
  let platform_version: PlatformVersion = match js_platform_version.is_undefined() {
60
- true => PlatformVersionWASM::PLATFORM_V1.into(),
61
+ true => PlatformVersionWASM::default().into(),
61
62
  false => PlatformVersionWASM::try_from(js_platform_version)?.into(),
62
63
  };
63
64
 
@@ -75,7 +76,8 @@ impl DataContractWASM {
75
76
 
76
77
  let definitions_value = Value::from(definitions);
77
78
 
78
- let data_contract_id = DataContract::generate_data_contract_id_v0(owner_id, identity_nonce);
79
+ let data_contract_id =
80
+ DataContract::generate_data_contract_id_v0(owner_id.get_bytes(), identity_nonce);
79
81
 
80
82
  let data_contract_id_value = Value::from(data_contract_id.to_string(Base58));
81
83
 
@@ -130,7 +132,7 @@ impl DataContractWASM {
130
132
  js_platform_version: JsValue,
131
133
  ) -> Result<DataContractWASM, JsValue> {
132
134
  let platform_version = match js_platform_version.is_undefined() {
133
- true => PlatformVersionWASM::PLATFORM_V1,
135
+ true => PlatformVersionWASM::default(),
134
136
  false => PlatformVersionWASM::try_from(js_platform_version)?,
135
137
  };
136
138
 
@@ -150,7 +152,7 @@ impl DataContractWASM {
150
152
  js_platform_version: JsValue,
151
153
  ) -> Result<DataContractWASM, JsValue> {
152
154
  let platform_version = match js_platform_version.is_undefined() {
153
- true => PlatformVersionWASM::PLATFORM_V1,
155
+ true => PlatformVersionWASM::default(),
154
156
  false => PlatformVersionWASM::try_from(js_platform_version)?,
155
157
  };
156
158
 
@@ -167,7 +169,7 @@ impl DataContractWASM {
167
169
  #[wasm_bindgen(js_name = "toBytes")]
168
170
  pub fn to_bytes(&self, js_platform_version: JsValue) -> Result<Vec<u8>, JsValue> {
169
171
  let platform_version = match js_platform_version.is_undefined() {
170
- true => PlatformVersionWASM::PLATFORM_V1,
172
+ true => PlatformVersionWASM::default(),
171
173
  false => PlatformVersionWASM::try_from(js_platform_version)?,
172
174
  };
173
175
 
@@ -181,7 +183,7 @@ impl DataContractWASM {
181
183
  #[wasm_bindgen(js_name = "toValue")]
182
184
  pub fn to_value(&self, js_platform_version: JsValue) -> Result<JsValue, JsValue> {
183
185
  let platform_version = match js_platform_version.is_undefined() {
184
- true => PlatformVersionWASM::PLATFORM_V1,
186
+ true => PlatformVersionWASM::default(),
185
187
  false => PlatformVersionWASM::try_from(js_platform_version)?,
186
188
  };
187
189
 
@@ -211,13 +213,13 @@ impl DataContractWASM {
211
213
  }
212
214
 
213
215
  #[wasm_bindgen(js_name = "getId")]
214
- pub fn get_id(&self) -> Vec<u8> {
215
- self.0.id().to_vec()
216
+ pub fn get_id(&self) -> IdentifierWASM {
217
+ self.0.id().into()
216
218
  }
217
219
 
218
220
  #[wasm_bindgen(js_name = "getOwnerId")]
219
- pub fn get_owner_id(&self) -> Vec<u8> {
220
- self.0.owner_id().to_vec()
221
+ pub fn get_owner_id(&self) -> IdentifierWASM {
222
+ self.0.owner_id().into()
221
223
  }
222
224
 
223
225
  #[wasm_bindgen(js_name = "getConfig")]
@@ -229,17 +231,17 @@ impl DataContractWASM {
229
231
  }
230
232
 
231
233
  #[wasm_bindgen(js_name = "setId")]
232
- pub fn set_id(&mut self, js_data_contract_id: JsValue) -> Result<(), JsValue> {
233
- let data_contract_id = identifier_from_js_value(&js_data_contract_id)?;
234
-
235
- Ok(self.0.set_id(data_contract_id))
234
+ pub fn set_id(&mut self, js_data_contract_id: &JsValue) -> Result<(), JsValue> {
235
+ self.0
236
+ .set_id(IdentifierWASM::try_from(js_data_contract_id)?.into());
237
+ Ok(())
236
238
  }
237
239
 
238
240
  #[wasm_bindgen(js_name = "setOwnerId")]
239
- pub fn set_owner_id(&mut self, js_owner_id: JsValue) -> Result<(), JsValue> {
240
- let owner_id = identifier_from_js_value(&js_owner_id)?;
241
-
242
- Ok(self.0.set_owner_id(owner_id))
241
+ pub fn set_owner_id(&mut self, js_owner_id: &JsValue) -> Result<(), JsValue> {
242
+ self.0
243
+ .set_owner_id(IdentifierWASM::try_from(js_owner_id)?.into());
244
+ Ok(())
243
245
  }
244
246
 
245
247
  #[wasm_bindgen(js_name = "setVersion")]
@@ -254,7 +256,7 @@ impl DataContractWASM {
254
256
  js_platform_version: JsValue,
255
257
  ) -> Result<(), JsValue> {
256
258
  let platform_version = match js_platform_version.is_undefined() {
257
- true => PlatformVersionWASM::PLATFORM_V1,
259
+ true => PlatformVersionWASM::default(),
258
260
  false => PlatformVersionWASM::try_from(js_platform_version)?,
259
261
  };
260
262
 
@@ -277,7 +279,7 @@ impl DataContractWASM {
277
279
  js_platform_version: JsValue,
278
280
  ) -> Result<(), JsValue> {
279
281
  let platform_version = match js_platform_version.is_undefined() {
280
- true => PlatformVersionWASM::PLATFORM_V1,
282
+ true => PlatformVersionWASM::default(),
281
283
  false => PlatformVersionWASM::try_from(js_platform_version)?,
282
284
  };
283
285
 
@@ -303,7 +305,7 @@ impl DataContractWASM {
303
305
  #[wasm_bindgen(js_name = "toJson")]
304
306
  pub fn to_json(&self, js_platform_version: JsValue) -> Result<JsValue, JsValue> {
305
307
  let platform_version = match js_platform_version.is_undefined() {
306
- true => PlatformVersionWASM::PLATFORM_V1,
308
+ true => PlatformVersionWASM::default(),
307
309
  false => PlatformVersionWASM::try_from(js_platform_version)?,
308
310
  };
309
311
 
@@ -315,12 +317,14 @@ impl DataContractWASM {
315
317
 
316
318
  #[wasm_bindgen(js_name = "generateId")]
317
319
  pub fn generate_id(
318
- js_owner_id: JsValue,
320
+ js_owner_id: &JsValue,
319
321
  identity_nonce: IdentityNonce,
320
- ) -> Result<Vec<u8>, JsValue> {
321
- let owner_id = identifier_from_js_value(&js_owner_id)?;
322
-
323
- Ok(DataContract::generate_data_contract_id_v0(owner_id, identity_nonce).to_vec())
322
+ ) -> Result<IdentifierWASM, JsValue> {
323
+ Ok(DataContract::generate_data_contract_id_v0(
324
+ IdentifierWASM::try_from(js_owner_id)?.get_bytes(),
325
+ identity_nonce,
326
+ )
327
+ .into())
324
328
  }
325
329
  }
326
330
 
@@ -4,7 +4,7 @@ version.workspace = true
4
4
  edition = "2024"
5
5
 
6
6
  [dependencies]
7
- wasm-bindgen = { version = "=0.2.100", features = ["serde-serialize"] }
7
+ wasm-bindgen = { version = "=0.2.100", default-features = false, features = ["serde-serialize"] }
8
8
  dpp = { git = "https://github.com/dashpay/platform", branch = "master", default-features = false, features = [
9
9
  "state-transition-signing"
10
10
  ]}
@@ -32,7 +32,7 @@ impl DataContractCreateTransitionWASM {
32
32
  let rs_data_contract: DataContract = data_contract.clone().into();
33
33
 
34
34
  let platform_version = match js_platform_version.is_undefined() {
35
- true => PlatformVersionWASM::PLATFORM_V1,
35
+ true => PlatformVersionWASM::default(),
36
36
  false => PlatformVersionWASM::try_from(js_platform_version)?,
37
37
  };
38
38
 
@@ -96,7 +96,7 @@ impl DataContractCreateTransitionWASM {
96
96
  js_platform_version: JsValue,
97
97
  ) -> Result<(), JsValue> {
98
98
  let platform_version = match js_platform_version.is_undefined() {
99
- true => PlatformVersionWASM::PLATFORM_V1,
99
+ true => PlatformVersionWASM::default(),
100
100
  false => PlatformVersionWASM::try_from(js_platform_version)?,
101
101
  };
102
102
 
@@ -119,7 +119,7 @@ impl DataContractCreateTransitionWASM {
119
119
  full_validation: Option<bool>,
120
120
  ) -> Result<DataContractWASM, JsValue> {
121
121
  let platform_version = match js_platform_version.is_undefined() {
122
- true => PlatformVersionWASM::PLATFORM_V1,
122
+ true => PlatformVersionWASM::default(),
123
123
  false => PlatformVersionWASM::try_from(js_platform_version)?,
124
124
  };
125
125
 
@@ -25,7 +25,7 @@ impl DataContractUpdateTransitionWASM {
25
25
  js_platform_version: JsValue,
26
26
  ) -> Result<DataContractUpdateTransitionWASM, JsValue> {
27
27
  let platform_version = match js_platform_version.is_undefined() {
28
- true => PlatformVersionWASM::PLATFORM_V1,
28
+ true => PlatformVersionWASM::default(),
29
29
  false => PlatformVersionWASM::try_from(js_platform_version)?,
30
30
  };
31
31
 
@@ -79,7 +79,7 @@ impl DataContractUpdateTransitionWASM {
79
79
  js_platform_version: JsValue,
80
80
  ) -> Result<(), JsValue> {
81
81
  let platform_version = match js_platform_version.is_undefined() {
82
- true => PlatformVersionWASM::PLATFORM_V1,
82
+ true => PlatformVersionWASM::default(),
83
83
  false => PlatformVersionWASM::try_from(js_platform_version)?,
84
84
  };
85
85
 
@@ -102,7 +102,7 @@ impl DataContractUpdateTransitionWASM {
102
102
  js_platform_version: JsValue,
103
103
  ) -> Result<DataContractWASM, JsValue> {
104
104
  let platform_version = match js_platform_version.is_undefined() {
105
- true => PlatformVersionWASM::PLATFORM_V1,
105
+ true => PlatformVersionWASM::default(),
106
106
  false => PlatformVersionWASM::try_from(js_platform_version)?,
107
107
  };
108
108
 
@@ -7,8 +7,9 @@ edition = "2024"
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
  pshenmic_dpp_utils = {path = "../utils"}
12
+ pshenmic_dpp_identifier = { path = "../identifier" }
12
13
  pshenmic_dpp_enums = {path = "../enums"}
13
14
  pshenmic_dpp_data_contract = {path = "../data_contract"}
14
15
  dpp = { git = "https://github.com/dashpay/platform", branch = "master", default-features = false, features = [