pshenmic-dpp 1.0.2 → 1.0.4

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 (36) hide show
  1. package/Cargo.lock +41 -13
  2. package/Cargo.toml +28 -10
  3. package/README.md +2 -0
  4. package/dist/wasm/pshenmic_dpp.js +1287 -289
  5. package/dist/wasm/pshenmic_dpp_bg.js +1 -1
  6. package/package.json +3 -2
  7. package/packages/{cbor-conversation → cbor_conversation}/Cargo.toml +0 -4
  8. package/packages/data_contract/Cargo.toml +17 -0
  9. package/packages/data_contract/src/lib.rs +162 -0
  10. package/packages/data_contract_transitions/Cargo.toml +14 -0
  11. package/packages/data_contract_transitions/src/create/mod.rs +154 -0
  12. package/packages/data_contract_transitions/src/lib.rs +2 -0
  13. package/packages/data_contract_transitions/src/update/mod.rs +135 -0
  14. package/packages/document/Cargo.toml +4 -6
  15. package/packages/document/src/lib.rs +44 -1
  16. package/packages/document/src/methods/js.rs +64 -8
  17. package/packages/document_batch/Cargo.toml +1 -8
  18. package/packages/document_batch/src/lib.rs +5 -4
  19. package/packages/enums/Cargo.toml +1 -5
  20. package/packages/enums/src/lib.rs +1 -0
  21. package/packages/enums/src/platform/mod.rs +38 -0
  22. package/packages/identity/Cargo.toml +4 -5
  23. package/packages/identity/src/lib.rs +23 -3
  24. package/packages/identity_transitions/Cargo.toml +1 -5
  25. package/packages/identity_transitions/src/create_transition/mod.rs +6 -6
  26. package/packages/mock_bls/Cargo.toml +1 -5
  27. package/packages/private_key/Cargo.toml +1 -5
  28. package/packages/private_key/src/lib.rs +1 -1
  29. package/packages/public_key/Cargo.toml +1 -5
  30. package/packages/public_key/src/lib.rs +5 -7
  31. package/packages/state_transition/Cargo.toml +1 -5
  32. package/packages/state_transition/src/lib.rs +11 -9
  33. package/packages/utils/Cargo.toml +1 -5
  34. package/scripts/build-js.sh +3 -2
  35. package/src/lib.rs +7 -1
  36. /package/packages/{cbor-conversation → cbor_conversation}/src/lib.rs +0 -0
@@ -12,13 +12,6 @@ pshenmic_dpp_document = {path = "../document"}
12
12
  pshenmic_dpp_enums = {path = "../enums"}
13
13
  pshenmic_dpp_utils = {path = "../utils"}
14
14
  pshenmic_dpp_state_transition = {path = "../state_transition"}
15
- pshenmic_dpp_mock_bls = {path = "../mock_bls"}
16
15
  dpp = { git = "https://github.com/dashpay/platform", branch = "master", default-features = false, features = [
17
16
  "document-json-conversion",
18
- "state-transition-signing"
19
- ]}
20
-
21
-
22
- [profile.release]
23
- lto = true
24
- opt-level = 'z'
17
+ ]}
@@ -83,7 +83,7 @@ impl From<(DocumentTransition, DocumentsBatchTransition)> for DocumentBatchWASM
83
83
 
84
84
  #[wasm_bindgen]
85
85
  impl DocumentBatchWASM {
86
- #[wasm_bindgen(js_name=new)]
86
+ #[wasm_bindgen(constructor)]
87
87
  pub fn new(
88
88
  batch_type: BatchType,
89
89
  document: DocumentWASM,
@@ -163,8 +163,8 @@ impl DocumentBatchWASM {
163
163
  StateTransitionWASM::from(st)
164
164
  }
165
165
 
166
- #[wasm_bindgen(js_name=toBuffer)]
167
- pub fn to_buffer(&self) -> Result<JsValue, JsValue> {
166
+ #[wasm_bindgen(js_name=toBytes)]
167
+ pub fn to_bytes(&self) -> Result<JsValue, JsValue> {
168
168
  let bytes = self.batch.serialize_to_bytes().with_js_error();
169
169
 
170
170
  match bytes {
@@ -195,7 +195,8 @@ impl DocumentBatchWASM {
195
195
  }
196
196
  }
197
197
 
198
- pub fn from_buffer(bytes: Vec<u8>) -> Result<DocumentBatchWASM, JsValue> {
198
+ #[wasm_bindgen(js_name=fromBytes)]
199
+ pub fn from_bytes(bytes: Vec<u8>) -> Result<DocumentBatchWASM, JsValue> {
199
200
  let batch_transition =
200
201
  DocumentsBatchTransition::deserialize_from_bytes(bytes.as_slice()).with_js_error();
201
202
 
@@ -10,8 +10,4 @@ crate-type = ["cdylib", "lib"]
10
10
  wasm-bindgen = "0.2.100"
11
11
  dpp = { git = "https://github.com/dashpay/platform", branch = "master", default-features = false, features = [
12
12
  "identity-value-conversion",
13
- ]}
14
-
15
- [profile.release]
16
- lto = true
17
- opt-level = 'z'
13
+ ]}
@@ -1,2 +1,3 @@
1
1
  pub mod batch;
2
2
  pub mod keys;
3
+ pub mod platform;
@@ -0,0 +1,38 @@
1
+ use dpp::version::PlatformVersion;
2
+ use dpp::version::v1::PLATFORM_V1;
3
+ use dpp::version::v2::PLATFORM_V2;
4
+ use dpp::version::v3::PLATFORM_V3;
5
+ use dpp::version::v4::PLATFORM_V4;
6
+ use dpp::version::v5::PLATFORM_V5;
7
+ use dpp::version::v6::PLATFORM_V6;
8
+ use dpp::version::v7::PLATFORM_V7;
9
+ use dpp::version::v8::PLATFORM_V8;
10
+ use wasm_bindgen::prelude::wasm_bindgen;
11
+
12
+ #[wasm_bindgen(js_name = "PlatformVersionWASM")]
13
+ #[allow(non_camel_case_types)]
14
+ 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,
23
+ }
24
+
25
+ impl From<PlatformVersionWASM> for PlatformVersion {
26
+ fn from(value: PlatformVersionWASM) -> Self {
27
+ match value {
28
+ PlatformVersionWASM::PLATFORM_V1 => PLATFORM_V1,
29
+ PlatformVersionWASM::PLATFORM_V2 => PLATFORM_V2,
30
+ PlatformVersionWASM::PLATFORM_V3 => PLATFORM_V3,
31
+ PlatformVersionWASM::PLATFORM_V4 => PLATFORM_V4,
32
+ PlatformVersionWASM::PLATFORM_V5 => PLATFORM_V5,
33
+ PlatformVersionWASM::PLATFORM_V6 => PLATFORM_V6,
34
+ PlatformVersionWASM::PLATFORM_V7 => PLATFORM_V7,
35
+ PlatformVersionWASM::PLATFORM_V8 => PLATFORM_V8,
36
+ }
37
+ }
38
+ }
@@ -8,10 +8,9 @@ crate-type = ["cdylib", "lib"]
8
8
 
9
9
  [dependencies]
10
10
  wasm-bindgen = { version = "=0.2.100", features = ["serde-serialize"] }
11
- dpp = { git = "https://github.com/dashpay/platform", branch = "master", default-features = false}
11
+ dpp = { git = "https://github.com/dashpay/platform", branch = "master", default-features = false, features = [
12
+ "identity-serialization"
13
+ ]}
12
14
  serde-wasm-bindgen = { git = "https://github.com/QuantumExplorer/serde-wasm-bindgen", branch = "feat/not_human_readable" }
13
15
  pshenmic_dpp_public_key = { path = "../public_key" }
14
-
15
- [profile.release]
16
- lto = true
17
- opt-level = 'z'
16
+ pshenmic_dpp_utils = { path = "../utils" }
@@ -2,8 +2,10 @@ use dpp::identifier::Identifier;
2
2
  use dpp::identity::accessors::{IdentityGettersV0, IdentitySettersV0};
3
3
  use dpp::identity::{Identity, KeyID};
4
4
  use dpp::platform_value::string_encoding::Encoding::Base58;
5
+ use dpp::serialization::{PlatformDeserializable, PlatformSerializable};
5
6
  use dpp::version::PlatformVersion;
6
7
  use pshenmic_dpp_public_key::IdentityPublicKeyWASM;
8
+ use pshenmic_dpp_utils::WithJsError;
7
9
  use wasm_bindgen::JsValue;
8
10
  use wasm_bindgen::prelude::wasm_bindgen;
9
11
 
@@ -13,13 +15,17 @@ pub struct IdentityWASM(Identity);
13
15
  #[wasm_bindgen]
14
16
  impl IdentityWASM {
15
17
  #[wasm_bindgen(constructor)]
16
- pub fn new(js_identifier: String) -> IdentityWASM {
18
+ pub fn new(js_identifier: String) -> Result<IdentityWASM, JsValue> {
17
19
  let identifier = Identifier::from_string(&*js_identifier, Base58);
18
20
 
19
21
  let identity =
20
- Identity::create_basic_identity(identifier.unwrap(), PlatformVersion::first()).unwrap();
22
+ Identity::create_basic_identity(identifier.unwrap(), PlatformVersion::first())
23
+ .with_js_error();
21
24
 
22
- IdentityWASM(identity)
25
+ match identity {
26
+ Ok(identity) => Ok(IdentityWASM(identity)),
27
+ Err(err) => Err(err),
28
+ }
23
29
  }
24
30
 
25
31
  #[wasm_bindgen(js_name = "setId")]
@@ -72,6 +78,20 @@ impl IdentityWASM {
72
78
  #[wasm_bindgen(js_name = "getPublicKeys")]
73
79
  pub fn get_public_keys(&self) -> JsValue {
74
80
  let keys = self.0.public_keys();
81
+
75
82
  serde_wasm_bindgen::to_value(keys).unwrap()
76
83
  }
84
+
85
+ #[wasm_bindgen(js_name = "toBytes")]
86
+ pub fn to_bytes(&self) -> Result<Vec<u8>, JsValue> {
87
+ self.0.serialize_to_bytes().with_js_error()
88
+ }
89
+
90
+ #[wasm_bindgen(js_name = "fromBytes")]
91
+ pub fn from_bytes(bytes: Vec<u8>) -> Result<IdentityWASM, JsValue> {
92
+ match Identity::deserialize_from_bytes(bytes.as_slice()).with_js_error() {
93
+ Ok(identity) => Ok(IdentityWASM(identity)),
94
+ Err(err) => Err(err),
95
+ }
96
+ }
77
97
  }
@@ -14,8 +14,4 @@ dpp = { git = "https://github.com/dashpay/platform", branch = "master", default-
14
14
  pshenmic_dpp_utils = {path = "../utils"}
15
15
  pshenmic_dpp_public_key = {path = "../public_key"}
16
16
  pshenmic_dpp_state_transition = {path = "../state_transition"}
17
- pshenmic_dpp_enums = {path = "../enums"}
18
-
19
- [profile.release]
20
- lto = true
21
- opt-level = 'z'
17
+ pshenmic_dpp_enums = {path = "../enums"}
@@ -64,8 +64,8 @@ impl IdentityCreateTransitionWASM {
64
64
  StateTransitionWASM::from(StateTransition::IdentityCreate(self.clone().0))
65
65
  }
66
66
 
67
- #[wasm_bindgen(js_name = "toBuffer")]
68
- pub fn to_buffer(&self) -> Result<JsValue, JsValue> {
67
+ #[wasm_bindgen(js_name = "toBytes")]
68
+ pub fn to_bytes(&self) -> Result<JsValue, JsValue> {
69
69
  let bytes = self.0.serialize_to_bytes().with_js_error();
70
70
 
71
71
  match bytes {
@@ -76,9 +76,9 @@ impl IdentityCreateTransitionWASM {
76
76
 
77
77
  #[wasm_bindgen(js_name = "fromStateTransition")]
78
78
  pub fn from_state_transition(
79
- st: StateTransitionWASM,
79
+ st: &StateTransitionWASM,
80
80
  ) -> Result<IdentityCreateTransitionWASM, JsValue> {
81
- let rs_st: StateTransition = st.into();
81
+ let rs_st: StateTransition = st.clone().into();
82
82
 
83
83
  match rs_st {
84
84
  StateTransition::IdentityCreate(st) => Ok(IdentityCreateTransitionWASM(st)),
@@ -86,8 +86,8 @@ impl IdentityCreateTransitionWASM {
86
86
  }
87
87
  }
88
88
 
89
- #[wasm_bindgen(js_name = "fromBuffer")]
90
- pub fn from_buffer(bytes: Vec<u8>) -> Result<IdentityCreateTransitionWASM, JsValue> {
89
+ #[wasm_bindgen(js_name = "fromBytes")]
90
+ pub fn from_bytes(bytes: Vec<u8>) -> Result<IdentityCreateTransitionWASM, JsValue> {
91
91
  let rs_transition =
92
92
  IdentityCreateTransition::deserialize_from_bytes(bytes.as_slice()).with_js_error();
93
93
 
@@ -9,8 +9,4 @@ crate-type = ["cdylib", "lib"]
9
9
  [dependencies]
10
10
  dpp = { git = "https://github.com/dashpay/platform", branch = "master", default-features = false, features = [
11
11
  "bls-signatures",
12
- ]}
13
-
14
- [profile.release]
15
- lto = true
16
- opt-level = 'z'
12
+ ]}
@@ -10,8 +10,4 @@ crate-type = ["cdylib", "lib"]
10
10
  wasm-bindgen = { version = "=0.2.100", features = ["serde-serialize"] }
11
11
  dpp = { git = "https://github.com/dashpay/platform", branch = "master", default-features = false, features = [
12
12
  "identity-value-conversion",
13
- ]}
14
-
15
- [profile.release]
16
- lto = true
17
- opt-level = 'z'
13
+ ]}
@@ -7,7 +7,7 @@ pub struct PrivateKeyWASM(PrivateKey);
7
7
 
8
8
  #[wasm_bindgen]
9
9
  impl PrivateKeyWASM {
10
- #[wasm_bindgen(js_name = "new")]
10
+ #[wasm_bindgen(constructor)]
11
11
  pub fn new(wif: &str) -> Result<Self, JsValue> {
12
12
  let pk = PrivateKey::from_wif(wif).map_err(|err| JsValue::from_str(&*err.to_string()));
13
13
 
@@ -12,8 +12,4 @@ dpp = { git = "https://github.com/dashpay/platform", branch = "master", default-
12
12
  "identity-value-conversion",
13
13
  ]}
14
14
  pshenmic_dpp_enums = {path = "../enums"}
15
- pshenmic_dpp_utils = {path = "../utils"}
16
-
17
- [profile.release]
18
- lto = true
19
- opt-level = 'z'
15
+ pshenmic_dpp_utils = {path = "../utils"}
@@ -128,16 +128,14 @@ impl IdentityPublicKeyWASM {
128
128
  self.0.set_disabled_at(disabled_at)
129
129
  }
130
130
 
131
- #[wasm_bindgen(js_name = toBuffer)]
132
- pub fn to_buffer(&self) -> Result<Vec<u8>, JsValue> {
131
+ #[wasm_bindgen(js_name = toBytes)]
132
+ pub fn to_byes(&self) -> Result<Vec<u8>, JsValue> {
133
133
  self.0.serialize_to_bytes().with_js_error()
134
134
  }
135
135
 
136
- #[wasm_bindgen(js_name = fromBuffer)]
137
- pub fn from_buffer(buffer: Vec<u8>) -> Result<IdentityPublicKeyWASM, JsValue> {
138
- let rs_pk = IdentityPublicKey::deserialize_from_bytes(buffer.as_slice()).with_js_error();
139
-
140
- match rs_pk {
136
+ #[wasm_bindgen(js_name = fromBytes)]
137
+ pub fn from_bytes(bytes: Vec<u8>) -> Result<IdentityPublicKeyWASM, JsValue> {
138
+ match IdentityPublicKey::deserialize_from_bytes(bytes.as_slice()).with_js_error() {
141
139
  Ok(pk) => Ok(IdentityPublicKeyWASM(pk)),
142
140
  Err(e) => Err(e),
143
141
  }
@@ -15,8 +15,4 @@ pshenmic_dpp_mock_bls = {path = "../mock_bls"}
15
15
  pshenmic_dpp_enums = {path = "../enums"}
16
16
  dpp = { git = "https://github.com/dashpay/platform", branch = "master", default-features = false, features = [
17
17
  "state-transition-signing"
18
- ]}
19
-
20
- [profile.release]
21
- lto = true
22
- opt-level = 'z'
18
+ ]}
@@ -9,6 +9,7 @@ use pshenmic_dpp_utils::WithJsError;
9
9
  use wasm_bindgen::JsValue;
10
10
  use wasm_bindgen::prelude::wasm_bindgen;
11
11
 
12
+ #[derive(Clone)]
12
13
  #[wasm_bindgen(js_name = "StateTransitionWASM")]
13
14
  pub struct StateTransitionWASM(StateTransition);
14
15
 
@@ -29,11 +30,11 @@ impl StateTransitionWASM {
29
30
  #[wasm_bindgen(js_name=sign)]
30
31
  pub fn sign(
31
32
  &mut self,
32
- private_key: PrivateKeyWASM,
33
- public_key: IdentityPublicKeyWASM,
33
+ private_key: &PrivateKeyWASM,
34
+ public_key: &IdentityPublicKeyWASM,
34
35
  ) -> Result<JsValue, JsValue> {
35
36
  let sig = self.0.sign(
36
- &public_key.into(),
37
+ &public_key.clone().into(),
37
38
  private_key.get_key_bytes().as_slice(),
38
39
  &MockBLS {},
39
40
  );
@@ -57,7 +58,7 @@ impl StateTransitionWASM {
57
58
  #[wasm_bindgen(js_name=signByPrivateKey)]
58
59
  pub fn sign_by_private_key(
59
60
  &mut self,
60
- private_key: PrivateKeyWASM,
61
+ private_key: &PrivateKeyWASM,
61
62
  key_type: KeyTypeWASM,
62
63
  ) -> JsValue {
63
64
  let _sig = self
@@ -77,15 +78,16 @@ impl StateTransitionWASM {
77
78
  }
78
79
  }
79
80
 
80
- #[wasm_bindgen(js_name=toBuffer)]
81
- pub fn to_buffer(&self) -> Result<JsValue, JsValue> {
82
- let bytes = self.0.serialize_to_bytes().expect("Serialization failed");
81
+ #[wasm_bindgen(js_name=toBytes)]
82
+ pub fn to_bytes(&self) -> Result<JsValue, JsValue> {
83
+ let bytes = self.0.serialize_to_bytes().with_js_error()?;
83
84
 
84
85
  Ok(JsValue::from(bytes.clone()))
85
86
  }
86
87
 
87
- pub fn from_buffer(buffer: Vec<u8>) -> Result<StateTransitionWASM, JsValue> {
88
- let st = StateTransition::deserialize_from_bytes(buffer.as_slice());
88
+ #[wasm_bindgen(js_name=fromBytes)]
89
+ pub fn from_bytes(bytes: Vec<u8>) -> Result<StateTransitionWASM, JsValue> {
90
+ let st = StateTransition::deserialize_from_bytes(bytes.as_slice());
89
91
 
90
92
  match st {
91
93
  Err(err) => Err(JsValue::from_str(err.to_string().as_str())),
@@ -17,8 +17,4 @@ js-sys = "0.3.53"
17
17
  serde_json = { version = "1.0", features = ["preserve_order"] }
18
18
  serde-wasm-bindgen = { git = "https://github.com/QuantumExplorer/serde-wasm-bindgen", branch = "feat/not_human_readable" }
19
19
  serde = { version = "1.0.197", features = ["derive"] }
20
- itertools = { version = "0.13" }
21
-
22
- [profile.release]
23
- lto = true
24
- opt-level = 'z'
20
+ itertools = { version = "0.13" }
@@ -15,12 +15,13 @@ WASM_BINARY_PATH="$WASM_DIR/pshenmic_dpp_bg.wasm"
15
15
  # Create directory in dist to save transpiled wasm code and TS typings
16
16
  mkdir -p $DIST_WASM_DIR
17
17
 
18
- ## Converting wasm into base64 and saving it to dist folder
19
18
 
20
19
  rm -rf $DIST_WASM_BINARY_BASE_64
21
20
  rm -rf $DIST_WASM_BINARY_RAW
22
21
  rm -rf $DIST_WASM_JS
23
22
 
23
+ ## Converting wasm into base64 and saving it to dist folder
24
+
24
25
  if [[ "${RAW}" == "true" ]]; then
25
26
  cp $WASM_BINARY_PATH $DIST_WASM_BINARY_RAW
26
27
  else
@@ -35,4 +36,4 @@ echo "Transpiling wasm ES Modules to CommonJS"
35
36
  cp $WASM_JS_CODE_PATH $DIST_WASM_JS
36
37
 
37
38
  echo "Cleaning wasm build"
38
- rm -rf $WASM_DIR
39
+ #rm -rf $WASM_DIR
package/src/lib.rs CHANGED
@@ -1,5 +1,11 @@
1
- pub use pshenmic_dpp_document_batch::DocumentBatchWASM;
1
+ #![no_std]
2
+ #![no_main]
3
+
4
+ pub use pshenmic_dpp_data_contract;
5
+ pub use pshenmic_dpp_data_contract_transitions;
6
+ pub use pshenmic_dpp_document_batch;
2
7
  pub use pshenmic_dpp_document_search;
8
+ pub use pshenmic_dpp_enums;
3
9
  pub use pshenmic_dpp_identity;
4
10
  pub use pshenmic_dpp_identity_transitions;
5
11
  pub use pshenmic_dpp_state_transition;