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,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
+ }
@@ -1,13 +1,13 @@
1
1
  [package]
2
2
  name = "pshenmic_dpp_document_search"
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
  "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
+ }
@@ -1,17 +1,18 @@
1
1
  [package]
2
2
  name = "pshenmic_dpp_data_contract"
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
  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
- "platform-value"
16
16
  ]}
17
+ js-sys = "0.3.53"
17
18
  serde-wasm-bindgen = { git = "https://github.com/QuantumExplorer/serde-wasm-bindgen", branch = "feat/not_human_readable" }