pshenmic-dpp 1.0.0

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 (40) hide show
  1. package/.editorconfig +10 -0
  2. package/.gitattributes +4 -0
  3. package/.github/workflows/build.yml +46 -0
  4. package/.github/workflows/publish.yml +42 -0
  5. package/Cargo.lock +2241 -0
  6. package/Cargo.toml +18 -0
  7. package/README.md +74 -0
  8. package/dist/wasm/pshenmic_dpp.js +1130 -0
  9. package/package.json +25 -0
  10. package/packages/cbor-conversation/Cargo.toml +17 -0
  11. package/packages/cbor-conversation/src/lib.rs +26 -0
  12. package/packages/document/Cargo.toml +15 -0
  13. package/packages/document/src/lib.rs +58 -0
  14. package/packages/document/src/methods/js.rs +204 -0
  15. package/packages/document/src/methods/mod.rs +2 -0
  16. package/packages/document/src/methods/rust.rs +92 -0
  17. package/packages/document_batch/Cargo.toml +20 -0
  18. package/packages/document_batch/src/generators.rs +63 -0
  19. package/packages/document_batch/src/lib.rs +326 -0
  20. package/packages/enums/Cargo.toml +13 -0
  21. package/packages/enums/src/batch/batch_enum.rs +19 -0
  22. package/packages/enums/src/batch/mod.rs +1 -0
  23. package/packages/enums/src/keys/key_type.rs +36 -0
  24. package/packages/enums/src/keys/mod.rs +3 -0
  25. package/packages/enums/src/keys/purpose.rs +41 -0
  26. package/packages/enums/src/keys/security_level.rs +32 -0
  27. package/packages/enums/src/lib.rs +2 -0
  28. package/packages/mock_bls/Cargo.toml +12 -0
  29. package/packages/mock_bls/src/lib.rs +26 -0
  30. package/packages/private_key/Cargo.toml +13 -0
  31. package/packages/private_key/src/lib.rs +35 -0
  32. package/packages/public_key/Cargo.toml +15 -0
  33. package/packages/public_key/src/lib.rs +125 -0
  34. package/packages/utils/Cargo.toml +20 -0
  35. package/packages/utils/src/buffer.rs +29 -0
  36. package/packages/utils/src/lib.rs +351 -0
  37. package/scripts/build-js.sh +38 -0
  38. package/scripts/build.sh +35 -0
  39. package/src/lib.rs +2 -0
  40. package/tsconfig.json +18 -0
@@ -0,0 +1,326 @@
1
+ use crate::generators::{
2
+ generate_create_transition, generate_delete_transition, generate_replace_transition,
3
+ };
4
+ use dpp::document::{Document, DocumentV0};
5
+ use dpp::identity::KeyType;
6
+ use dpp::prelude::IdentityNonce;
7
+ use dpp::serialization::{PlatformDeserializable, PlatformSerializable};
8
+ use dpp::state_transition::documents_batch_transition::accessors::DocumentsBatchTransitionAccessorsV0;
9
+ use dpp::state_transition::documents_batch_transition::document_base_transition::v0::v0_methods::DocumentBaseTransitionV0Methods;
10
+ use dpp::state_transition::documents_batch_transition::document_create_transition::v0::v0_methods::DocumentCreateTransitionV0Methods;
11
+ use dpp::state_transition::documents_batch_transition::document_transition::{
12
+ DocumentTransition, DocumentTransitionV0Methods,
13
+ };
14
+ use dpp::state_transition::documents_batch_transition::{
15
+ DocumentCreateTransition, DocumentDeleteTransition, DocumentReplaceTransition,
16
+ DocumentsBatchTransition, DocumentsBatchTransitionV0,
17
+ };
18
+ use dpp::state_transition::{StateTransition, StateTransitionIdentitySigned, StateTransitionLike};
19
+ use pshenmic_dpp_document::DocumentWASM;
20
+ use pshenmic_dpp_enums::batch::batch_enum::BatchType;
21
+ use pshenmic_dpp_enums::keys::key_type::KeyTypeWASM;
22
+ use pshenmic_dpp_mock_bls::MockBLS;
23
+ use pshenmic_dpp_private_key::PrivateKeyWASM;
24
+ use pshenmic_dpp_public_key::IdentityPublicKeyWASM;
25
+ use pshenmic_dpp_utils::WithJsError;
26
+ use std::collections::BTreeMap;
27
+ use wasm_bindgen::JsValue;
28
+ use wasm_bindgen::prelude::wasm_bindgen;
29
+
30
+ mod generators;
31
+
32
+ #[derive(Debug, Clone, PartialEq)]
33
+ #[wasm_bindgen(js_name=DocumentBatchWASM)]
34
+ pub struct DocumentBatchWASM {
35
+ batch: DocumentsBatchTransition,
36
+ document: DocumentWASM,
37
+ }
38
+
39
+ #[wasm_bindgen]
40
+ impl DocumentBatchWASM {
41
+ #[wasm_bindgen(js_name=new)]
42
+ pub fn new(
43
+ batch_type: BatchType,
44
+ document: DocumentWASM,
45
+ identity_contract_nonce: IdentityNonce,
46
+ ) -> Result<DocumentBatchWASM, JsValue> {
47
+ let data_contract_id = document.get_data_contract_id();
48
+ let document_type_name = document.get_document_type_name();
49
+
50
+ match document.get_entropy() {
51
+ Some(_entropy) => Ok(match batch_type {
52
+ BatchType::CREATE => {
53
+ let create_transition: DocumentCreateTransition = generate_create_transition(
54
+ document.clone(),
55
+ identity_contract_nonce,
56
+ document_type_name.to_string(),
57
+ data_contract_id,
58
+ );
59
+
60
+ DocumentBatchWASM {
61
+ batch: DocumentsBatchTransition::V0(DocumentsBatchTransitionV0 {
62
+ owner_id: document.get_owner_id(),
63
+ transitions: [DocumentTransition::Create(create_transition)].to_vec(),
64
+ user_fee_increase: 0,
65
+ signature_public_key_id: 0,
66
+ signature: Default::default(),
67
+ }),
68
+ document,
69
+ }
70
+ }
71
+ BatchType::DELETE => {
72
+ let delete_transition: DocumentDeleteTransition = generate_delete_transition(
73
+ document.clone(),
74
+ identity_contract_nonce,
75
+ document_type_name.to_string(),
76
+ data_contract_id,
77
+ );
78
+
79
+ DocumentBatchWASM {
80
+ batch: DocumentsBatchTransition::V0(DocumentsBatchTransitionV0 {
81
+ owner_id: document.get_owner_id(),
82
+ transitions: [DocumentTransition::Delete(delete_transition)].to_vec(),
83
+ user_fee_increase: 0,
84
+ signature_public_key_id: 0,
85
+ signature: Default::default(),
86
+ }),
87
+ document,
88
+ }
89
+ }
90
+ BatchType::REPLACE => {
91
+ let replace_transition: DocumentReplaceTransition = generate_replace_transition(
92
+ document.clone(),
93
+ identity_contract_nonce,
94
+ document_type_name.to_string(),
95
+ data_contract_id,
96
+ );
97
+
98
+ DocumentBatchWASM {
99
+ batch: DocumentsBatchTransition::V0(DocumentsBatchTransitionV0 {
100
+ owner_id: document.get_owner_id(),
101
+ transitions: [DocumentTransition::Replace(replace_transition)].to_vec(),
102
+ user_fee_increase: 0,
103
+ signature_public_key_id: 0,
104
+ signature: Default::default(),
105
+ }),
106
+ document,
107
+ }
108
+ }
109
+ }),
110
+ None => wasm_bindgen::throw_str("Entropy is empty"),
111
+ }
112
+ }
113
+ #[wasm_bindgen(js_name=sign)]
114
+ pub fn sign(
115
+ &mut self,
116
+ private_key: PrivateKeyWASM,
117
+ public_key: IdentityPublicKeyWASM,
118
+ ) -> Result<JsValue, JsValue> {
119
+ let mut st = StateTransition::from(self.batch.clone());
120
+
121
+ let sig = st.sign(
122
+ &public_key.get_key(),
123
+ private_key.get_key().to_bytes().as_slice(),
124
+ &MockBLS {},
125
+ );
126
+
127
+ let bytes = match sig {
128
+ Ok(_sig) => {
129
+ self.batch.set_signature(st.signature().clone());
130
+ self.batch
131
+ .set_signature_public_key_id(st.signature_public_key_id().unwrap());
132
+ st.serialize_to_bytes()
133
+ }
134
+ Err(e) => wasm_bindgen::throw_str(&e.to_string()),
135
+ };
136
+
137
+ match bytes {
138
+ Ok(bytes) => Ok(JsValue::from(bytes.clone())),
139
+ Err(e) => Ok(JsValue::from_str(&format!("{}", e))),
140
+ }
141
+ }
142
+
143
+ #[wasm_bindgen(js_name=signByPrivateKey)]
144
+ pub fn sign_by_private_key(
145
+ &mut self,
146
+ private_key: PrivateKeyWASM,
147
+ key_type: KeyTypeWASM,
148
+ ) -> JsValue {
149
+ let mut st = StateTransition::from(self.batch.clone());
150
+
151
+ let _sig = st
152
+ .sign_by_private_key(
153
+ &private_key.get_key().to_bytes().as_slice(),
154
+ KeyType::from(key_type),
155
+ &MockBLS {},
156
+ )
157
+ .with_js_error();
158
+
159
+ self.batch.set_signature(st.signature().clone());
160
+ self.batch
161
+ .set_signature_public_key_id(st.signature_public_key_id().unwrap());
162
+
163
+ let bytes = st.serialize_to_bytes().with_js_error();
164
+
165
+ match bytes {
166
+ Ok(bytes) => JsValue::from(bytes.clone()),
167
+ Err(err) => err,
168
+ }
169
+ }
170
+
171
+ #[wasm_bindgen(js_name=toBuffer)]
172
+ pub fn to_buffer(&self) -> Result<JsValue, JsValue> {
173
+ let bytes = &StateTransition::from(self.batch.clone())
174
+ .serialize_to_bytes()
175
+ .expect("Serialization failed");
176
+
177
+ Ok(JsValue::from(bytes.clone()))
178
+ }
179
+
180
+ #[wasm_bindgen(js_name=fromBuffer)]
181
+ pub fn from_buffer(bytes: Vec<u8>) -> Result<DocumentBatchWASM, JsValue> {
182
+ let batch = &StateTransition::deserialize_from_bytes(bytes.as_slice()).with_js_error()?;
183
+
184
+ match batch {
185
+ StateTransition::DocumentsBatch(batch) => {
186
+ let transition = batch.transitions().first();
187
+
188
+ match transition {
189
+ None => Err(JsValue::from_str("No transition")),
190
+ Some(document_transition) => {
191
+ let data_contract_id = document_transition.base().data_contract_id();
192
+ let document_type_name = document_transition.base().document_type_name();
193
+ let entropy = document_transition.entropy();
194
+
195
+ let document: DocumentV0 = match document_transition {
196
+ DocumentTransition::Create(create_transition) => DocumentV0 {
197
+ id: document_transition.get_id(),
198
+ owner_id: batch.owner_id(),
199
+ properties: create_transition.data().clone(),
200
+ revision: document_transition.revision(),
201
+ created_at: None,
202
+ updated_at: None,
203
+ transferred_at: None,
204
+ created_at_block_height: None,
205
+ updated_at_block_height: None,
206
+ transferred_at_block_height: None,
207
+ created_at_core_block_height: None,
208
+ updated_at_core_block_height: None,
209
+ transferred_at_core_block_height: None,
210
+ },
211
+ DocumentTransition::Replace(_replace_transition) => DocumentV0 {
212
+ id: document_transition.get_id(),
213
+ owner_id: batch.owner_id(),
214
+ properties: BTreeMap::new(),
215
+ revision: document_transition.revision(),
216
+ created_at: None,
217
+ updated_at: None,
218
+ transferred_at: None,
219
+ created_at_block_height: None,
220
+ updated_at_block_height: None,
221
+ transferred_at_block_height: None,
222
+ created_at_core_block_height: None,
223
+ updated_at_core_block_height: None,
224
+ transferred_at_core_block_height: None,
225
+ },
226
+ DocumentTransition::Delete(_delete_transition) => DocumentV0 {
227
+ id: document_transition.get_id(),
228
+ owner_id: batch.owner_id(),
229
+ properties: BTreeMap::new(),
230
+ revision: document_transition.revision(),
231
+ created_at: None,
232
+ updated_at: None,
233
+ transferred_at: None,
234
+ created_at_block_height: None,
235
+ updated_at_block_height: None,
236
+ transferred_at_block_height: None,
237
+ created_at_core_block_height: None,
238
+ updated_at_core_block_height: None,
239
+ transferred_at_core_block_height: None,
240
+ },
241
+ DocumentTransition::Transfer(_transfer_transition) => DocumentV0 {
242
+ id: document_transition.get_id(),
243
+ owner_id: batch.owner_id(),
244
+ properties: BTreeMap::new(),
245
+ revision: document_transition.revision(),
246
+ created_at: None,
247
+ updated_at: None,
248
+ transferred_at: None,
249
+ created_at_block_height: None,
250
+ updated_at_block_height: None,
251
+ transferred_at_block_height: None,
252
+ created_at_core_block_height: None,
253
+ updated_at_core_block_height: None,
254
+ transferred_at_core_block_height: None,
255
+ },
256
+ DocumentTransition::UpdatePrice(_update_price_transition) => {
257
+ DocumentV0 {
258
+ id: document_transition.get_id(),
259
+ owner_id: batch.owner_id(),
260
+ properties: BTreeMap::new(),
261
+ revision: document_transition.revision(),
262
+ created_at: None,
263
+ updated_at: None,
264
+ transferred_at: None,
265
+ created_at_block_height: None,
266
+ updated_at_block_height: None,
267
+ transferred_at_block_height: None,
268
+ created_at_core_block_height: None,
269
+ updated_at_core_block_height: None,
270
+ transferred_at_core_block_height: None,
271
+ }
272
+ }
273
+ DocumentTransition::Purchase(_purchase_transition) => DocumentV0 {
274
+ id: document_transition.get_id(),
275
+ owner_id: batch.owner_id(),
276
+ properties: BTreeMap::new(),
277
+ revision: document_transition.revision(),
278
+ created_at: None,
279
+ updated_at: None,
280
+ transferred_at: None,
281
+ created_at_block_height: None,
282
+ updated_at_block_height: None,
283
+ transferred_at_block_height: None,
284
+ created_at_core_block_height: None,
285
+ updated_at_core_block_height: None,
286
+ transferred_at_core_block_height: None,
287
+ },
288
+ };
289
+
290
+ let normal_entropy = match entropy {
291
+ Some(entropy) => {
292
+ let mut entropy_sized = [0u8; 32];
293
+ let bytes = entropy.as_slice();
294
+ let len = bytes.len().min(32);
295
+ entropy_sized[..len].copy_from_slice(&bytes[..len]);
296
+ Some(entropy_sized)
297
+ }
298
+ None => None,
299
+ };
300
+
301
+ Ok(DocumentBatchWASM {
302
+ batch: batch.clone(),
303
+ document: DocumentWASM::from_batch(
304
+ Document::V0(document),
305
+ data_contract_id,
306
+ document_type_name.to_string(),
307
+ normal_entropy,
308
+ ),
309
+ })
310
+ }
311
+ }
312
+ }
313
+ _ => Err(JsValue::from_str("incorrect batch type")),
314
+ }
315
+ }
316
+
317
+ #[wasm_bindgen(js_name=getDocument)]
318
+ pub fn get_document(&self) -> DocumentWASM {
319
+ self.document.clone()
320
+ }
321
+
322
+ #[wasm_bindgen(js_name=getSignature)]
323
+ pub fn get_signature(&self) -> Vec<u8> {
324
+ self.batch.signature().to_vec()
325
+ }
326
+ }
@@ -0,0 +1,13 @@
1
+ [package]
2
+ name = "pshenmic_dpp_enums"
3
+ version = "0.1.0"
4
+ edition = "2024"
5
+
6
+ [lib]
7
+ crate-type = ["cdylib", "lib"]
8
+
9
+ [dependencies]
10
+ wasm-bindgen = "0.2.100"
11
+ dpp = { git = "https://github.com/dashpay/platform", branch = "master", default-features = false, features = [
12
+ "identity-value-conversion",
13
+ ]}
@@ -0,0 +1,19 @@
1
+ use wasm_bindgen::prelude::wasm_bindgen;
2
+
3
+ #[wasm_bindgen(js_name = "BatchType")]
4
+ pub enum BatchType {
5
+ CREATE,
6
+ REPLACE,
7
+ DELETE,
8
+ }
9
+
10
+ impl From<u8> for BatchType {
11
+ fn from(value: u8) -> Self {
12
+ match value {
13
+ 0 => BatchType::CREATE,
14
+ 1 => BatchType::REPLACE,
15
+ 2 => BatchType::DELETE,
16
+ _ => panic!("Invalid BatchType"),
17
+ }
18
+ }
19
+ }
@@ -0,0 +1 @@
1
+ pub mod batch_enum;
@@ -0,0 +1,36 @@
1
+ use dpp::identity::KeyType;
2
+ use wasm_bindgen::prelude::wasm_bindgen;
3
+
4
+ #[allow(non_camel_case_types)]
5
+ #[wasm_bindgen(js_name = "KeyType")]
6
+ pub enum KeyTypeWASM {
7
+ ECDSA_SECP256K1 = 0,
8
+ BLS12_381 = 1,
9
+ ECDSA_HASH160 = 2,
10
+ BIP13_SCRIPT_HASH = 3,
11
+ EDDSA_25519_HASH160 = 4,
12
+ }
13
+
14
+ impl From<KeyTypeWASM> for KeyType {
15
+ fn from(key_type: KeyTypeWASM) -> Self {
16
+ match key_type {
17
+ KeyTypeWASM::ECDSA_SECP256K1 => KeyType::ECDSA_SECP256K1,
18
+ KeyTypeWASM::BLS12_381 => KeyType::BLS12_381,
19
+ KeyTypeWASM::ECDSA_HASH160 => KeyType::ECDSA_HASH160,
20
+ KeyTypeWASM::BIP13_SCRIPT_HASH => KeyType::BIP13_SCRIPT_HASH,
21
+ KeyTypeWASM::EDDSA_25519_HASH160 => KeyType::EDDSA_25519_HASH160,
22
+ }
23
+ }
24
+ }
25
+
26
+ impl From<KeyType> for KeyTypeWASM {
27
+ fn from(key_type: KeyType) -> Self {
28
+ match key_type {
29
+ KeyType::ECDSA_SECP256K1 => KeyTypeWASM::ECDSA_SECP256K1,
30
+ KeyType::BLS12_381 => KeyTypeWASM::BLS12_381,
31
+ KeyType::ECDSA_HASH160 => KeyTypeWASM::ECDSA_HASH160,
32
+ KeyType::BIP13_SCRIPT_HASH => KeyTypeWASM::BIP13_SCRIPT_HASH,
33
+ KeyType::EDDSA_25519_HASH160 => KeyTypeWASM::EDDSA_25519_HASH160,
34
+ }
35
+ }
36
+ }
@@ -0,0 +1,3 @@
1
+ pub mod key_type;
2
+ pub mod purpose;
3
+ pub mod security_level;
@@ -0,0 +1,41 @@
1
+ use dpp::identity::Purpose;
2
+ use wasm_bindgen::prelude::wasm_bindgen;
3
+
4
+ #[wasm_bindgen(js_name = "Purpose")]
5
+ pub enum PurposeWASM {
6
+ AUTHENTICATION = 0,
7
+ ENCRYPTION = 1,
8
+ DECRYPTION = 2,
9
+ TRANSFER = 3,
10
+ SYSTEM = 4,
11
+ VOTING = 5,
12
+ OWNER = 6,
13
+ }
14
+
15
+ impl From<PurposeWASM> for Purpose {
16
+ fn from(purpose: PurposeWASM) -> Self {
17
+ match purpose {
18
+ PurposeWASM::AUTHENTICATION => Purpose::AUTHENTICATION,
19
+ PurposeWASM::ENCRYPTION => Purpose::ENCRYPTION,
20
+ PurposeWASM::DECRYPTION => Purpose::DECRYPTION,
21
+ PurposeWASM::TRANSFER => Purpose::TRANSFER,
22
+ PurposeWASM::SYSTEM => Purpose::SYSTEM,
23
+ PurposeWASM::VOTING => Purpose::VOTING,
24
+ PurposeWASM::OWNER => Purpose::OWNER,
25
+ }
26
+ }
27
+ }
28
+
29
+ impl From<Purpose> for PurposeWASM {
30
+ fn from(purpose: Purpose) -> Self {
31
+ match purpose {
32
+ Purpose::AUTHENTICATION => PurposeWASM::AUTHENTICATION,
33
+ Purpose::ENCRYPTION => PurposeWASM::ENCRYPTION,
34
+ Purpose::DECRYPTION => PurposeWASM::DECRYPTION,
35
+ Purpose::TRANSFER => PurposeWASM::TRANSFER,
36
+ Purpose::SYSTEM => PurposeWASM::SYSTEM,
37
+ Purpose::VOTING => PurposeWASM::VOTING,
38
+ Purpose::OWNER => PurposeWASM::OWNER,
39
+ }
40
+ }
41
+ }
@@ -0,0 +1,32 @@
1
+ use dpp::identity::SecurityLevel;
2
+ use wasm_bindgen::prelude::wasm_bindgen;
3
+
4
+ #[wasm_bindgen(js_name = SecurityLevel)]
5
+ pub enum SecurityLevelWASM {
6
+ MASTER = 0,
7
+ CRITICAL = 1,
8
+ HIGH = 2,
9
+ MEDIUM = 3,
10
+ }
11
+
12
+ impl From<SecurityLevelWASM> for SecurityLevel {
13
+ fn from(security_level: SecurityLevelWASM) -> Self {
14
+ match security_level {
15
+ SecurityLevelWASM::MASTER => SecurityLevel::MASTER,
16
+ SecurityLevelWASM::CRITICAL => SecurityLevel::CRITICAL,
17
+ SecurityLevelWASM::HIGH => SecurityLevel::HIGH,
18
+ SecurityLevelWASM::MEDIUM => SecurityLevel::MEDIUM,
19
+ }
20
+ }
21
+ }
22
+
23
+ impl From<SecurityLevel> for SecurityLevelWASM {
24
+ fn from(security_level: SecurityLevel) -> Self {
25
+ match security_level {
26
+ SecurityLevel::MASTER => SecurityLevelWASM::MASTER,
27
+ SecurityLevel::CRITICAL => SecurityLevelWASM::CRITICAL,
28
+ SecurityLevel::HIGH => SecurityLevelWASM::HIGH,
29
+ SecurityLevel::MEDIUM => SecurityLevelWASM::MEDIUM,
30
+ }
31
+ }
32
+ }
@@ -0,0 +1,2 @@
1
+ pub mod batch;
2
+ pub mod keys;
@@ -0,0 +1,12 @@
1
+ [package]
2
+ name = "pshenmic_dpp_mock_bls"
3
+ version = "0.1.0"
4
+ edition = "2024"
5
+
6
+ [lib]
7
+ crate-type = ["cdylib", "lib"]
8
+
9
+ [dependencies]
10
+ dpp = { git = "https://github.com/dashpay/platform", branch = "master", default-features = false, features = [
11
+ "bls-signatures",
12
+ ]}
@@ -0,0 +1,26 @@
1
+ use dpp::{BlsModule, ProtocolError, PublicKeyValidationError};
2
+
3
+ pub struct MockBLS {}
4
+
5
+ impl BlsModule for MockBLS {
6
+ fn validate_public_key(&self, _pk: &[u8]) -> Result<(), PublicKeyValidationError> {
7
+ panic!("BLS signatures are not implemented");
8
+ }
9
+
10
+ fn verify_signature(
11
+ &self,
12
+ _signature: &[u8],
13
+ _data: &[u8],
14
+ _public_key: &[u8],
15
+ ) -> Result<bool, ProtocolError> {
16
+ panic!("BLS signatures are not implemented");
17
+ }
18
+
19
+ fn private_key_to_public_key(&self, _private_key: &[u8]) -> Result<Vec<u8>, ProtocolError> {
20
+ panic!("BLS signatures are not implemented");
21
+ }
22
+
23
+ fn sign(&self, _data: &[u8], _private_key: &[u8]) -> Result<Vec<u8>, ProtocolError> {
24
+ panic!("BLS signatures are not implemented");
25
+ }
26
+ }
@@ -0,0 +1,13 @@
1
+ [package]
2
+ name = "pshenmic_dpp_private_key"
3
+ version = "0.1.0"
4
+ edition = "2024"
5
+
6
+ [lib]
7
+ crate-type = ["cdylib", "lib"]
8
+
9
+ [dependencies]
10
+ wasm-bindgen = { version = "=0.2.100", features = ["serde-serialize"] }
11
+ dpp = { git = "https://github.com/dashpay/platform", branch = "master", default-features = false, features = [
12
+ "identity-value-conversion",
13
+ ]}
@@ -0,0 +1,35 @@
1
+ use dpp::dashcore::PrivateKey;
2
+ use wasm_bindgen::prelude::wasm_bindgen;
3
+
4
+ #[wasm_bindgen(js_name = "PrivateKeyWASM")]
5
+ pub struct PrivateKeyWASM {
6
+ private_key: PrivateKey,
7
+ }
8
+
9
+ #[wasm_bindgen]
10
+ impl PrivateKeyWASM {
11
+ #[wasm_bindgen(js_name = "new")]
12
+ pub fn new(wif: &str) -> Self {
13
+ let pk = PrivateKey::from_wif(wif).expect("Unable to parse private key");
14
+
15
+ PrivateKeyWASM { private_key: pk }
16
+ }
17
+ }
18
+
19
+ impl PrivateKeyWASM {
20
+ pub fn get_key(&self) -> PrivateKey {
21
+ self.private_key
22
+ }
23
+
24
+ pub fn get_key_inner(&self) -> [u8; 32] {
25
+ self.private_key.inner.secret_bytes()
26
+ }
27
+ }
28
+
29
+ #[wasm_bindgen]
30
+ impl PrivateKeyWASM {
31
+ #[wasm_bindgen(js_name = "getKeyWIF")]
32
+ pub fn get_key_wif(&self) -> String {
33
+ self.private_key.to_wif()
34
+ }
35
+ }
@@ -0,0 +1,15 @@
1
+ [package]
2
+ name = "pshenmic_dpp_public_key"
3
+ version = "0.1.0"
4
+ edition = "2024"
5
+
6
+ [lib]
7
+ crate-type = ["cdylib", "lib"]
8
+
9
+ [dependencies]
10
+ wasm-bindgen = { version = "=0.2.100", features = ["serde-serialize"] }
11
+ js-sys = "0.3.77"
12
+ dpp = { git = "https://github.com/dashpay/platform", branch = "master", features = [
13
+ "identity-value-conversion",
14
+ ]}
15
+ pshenmic_dpp_enums = {path = "../enums"}