pshenmic-dpp 1.0.0 → 1.0.2

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.
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "pshenmic-dpp",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "main": "dist/wasm/pshenmic_dpp.js",
5
5
  "repository": {
6
6
  "type": "git",
7
- "url": "https://github.com/owl352/pshemic-dpp"
7
+ "url": "https://github.com/owl352/pshenmic-dpp"
8
8
  },
9
9
  "scripts": {
10
10
  "tsc": "tsc",
@@ -20,6 +20,5 @@
20
20
  "babel": "^6.23.0",
21
21
  "babel-cli": "^6.26.0",
22
22
  "typescript": "^5.8.2"
23
- },
24
- "packageManager": "yarn@1.22.19+sha1.4ba7fc5c6e704fce2066ecbfb0b0d8976fe62447"
23
+ }
25
24
  }
@@ -9,9 +9,13 @@ crate-type = ["cdylib", "lib"]
9
9
  [dependencies]
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
- "cbor"
12
+ "cbor",
13
13
  ]}
14
14
  pshenmic_dpp_utils = {path = "../utils"}
15
15
  base64 = "0.22.1"
16
- ciborium = "0.2.0"
16
+ ciborium = "0.2.2"
17
17
  serde-wasm-bindgen = { git = "https://github.com/QuantumExplorer/serde-wasm-bindgen", branch = "feat/not_human_readable" }
18
+
19
+ [profile.release]
20
+ lto = true
21
+ opt-level = 'z'
@@ -1,7 +1,5 @@
1
1
  use base64::Engine;
2
2
  use base64::prelude::BASE64_STANDARD;
3
- use ciborium;
4
- use ciborium::Value;
5
3
  use dpp::util::cbor_serializer::serializable_value_to_cbor;
6
4
  use pshenmic_dpp_utils::with_serde_to_platform_value;
7
5
  use wasm_bindgen::JsValue;
@@ -20,7 +18,7 @@ pub fn object_to_cbor(object: &JsValue) -> String {
20
18
  pub fn cbor_to_object(cbor: String) -> JsValue {
21
19
  let base64_bytes = BASE64_STANDARD.decode(cbor).unwrap();
22
20
 
23
- let cbor: Value = ciborium::de::from_reader(base64_bytes.as_slice()).expect("REASON");
21
+ let cbor: ciborium::Value = ciborium::de::from_reader(base64_bytes.as_slice()).expect("REASON");
24
22
 
25
23
  serde_wasm_bindgen::to_value(&cbor).unwrap()
26
24
  }
@@ -13,3 +13,7 @@ dpp = { git = "https://github.com/dashpay/platform", branch = "master", default-
13
13
  "document-json-conversion"
14
14
  ]}
15
15
  serde-wasm-bindgen = { git = "https://github.com/QuantumExplorer/serde-wasm-bindgen", branch = "feat/not_human_readable" }
16
+
17
+ [profile.release]
18
+ lto = true
19
+ opt-level = 'z'
@@ -10,11 +10,15 @@ crate-type = ["cdylib", "lib"]
10
10
  wasm-bindgen = { version = "=0.2.100", features = ["serde-serialize"] }
11
11
  pshenmic_dpp_document = {path = "../document"}
12
12
  pshenmic_dpp_enums = {path = "../enums"}
13
- pshenmic_dpp_public_key = {path = "../public_key"}
14
- pshenmic_dpp_private_key = {path = "../private_key"}
15
13
  pshenmic_dpp_utils = {path = "../utils"}
14
+ pshenmic_dpp_state_transition = {path = "../state_transition"}
16
15
  pshenmic_dpp_mock_bls = {path = "../mock_bls"}
17
16
  dpp = { git = "https://github.com/dashpay/platform", branch = "master", default-features = false, features = [
18
17
  "document-json-conversion",
19
18
  "state-transition-signing"
20
19
  ]}
20
+
21
+
22
+ [profile.release]
23
+ lto = true
24
+ opt-level = 'z'
@@ -2,12 +2,10 @@ use crate::generators::{
2
2
  generate_create_transition, generate_delete_transition, generate_replace_transition,
3
3
  };
4
4
  use dpp::document::{Document, DocumentV0};
5
- use dpp::identity::KeyType;
6
5
  use dpp::prelude::IdentityNonce;
7
6
  use dpp::serialization::{PlatformDeserializable, PlatformSerializable};
8
7
  use dpp::state_transition::documents_batch_transition::accessors::DocumentsBatchTransitionAccessorsV0;
9
8
  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
9
  use dpp::state_transition::documents_batch_transition::document_transition::{
12
10
  DocumentTransition, DocumentTransitionV0Methods,
13
11
  };
@@ -15,13 +13,10 @@ use dpp::state_transition::documents_batch_transition::{
15
13
  DocumentCreateTransition, DocumentDeleteTransition, DocumentReplaceTransition,
16
14
  DocumentsBatchTransition, DocumentsBatchTransitionV0,
17
15
  };
18
- use dpp::state_transition::{StateTransition, StateTransitionIdentitySigned, StateTransitionLike};
16
+ use dpp::state_transition::{StateTransition, StateTransitionLike};
19
17
  use pshenmic_dpp_document::DocumentWASM;
20
18
  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;
19
+ use pshenmic_dpp_state_transition::StateTransitionWASM;
25
20
  use pshenmic_dpp_utils::WithJsError;
26
21
  use std::collections::BTreeMap;
27
22
  use wasm_bindgen::JsValue;
@@ -36,6 +31,56 @@ pub struct DocumentBatchWASM {
36
31
  document: DocumentWASM,
37
32
  }
38
33
 
34
+ impl From<(DocumentTransition, DocumentsBatchTransition)> for DocumentBatchWASM {
35
+ fn from(
36
+ (document_transition, batch): (DocumentTransition, DocumentsBatchTransition),
37
+ ) -> DocumentBatchWASM {
38
+ let data_contract_id = document_transition.base().data_contract_id();
39
+ let document_type_name = document_transition.base().document_type_name();
40
+ let entropy = document_transition.entropy();
41
+
42
+ let default = BTreeMap::new();
43
+ let properties = document_transition.data().unwrap_or(&default);
44
+
45
+ let document = DocumentV0 {
46
+ id: document_transition.get_id(),
47
+ owner_id: batch.owner_id(),
48
+ properties: properties.clone(),
49
+ revision: document_transition.revision(),
50
+ created_at: None,
51
+ updated_at: None,
52
+ transferred_at: None,
53
+ created_at_block_height: None,
54
+ updated_at_block_height: None,
55
+ transferred_at_block_height: None,
56
+ created_at_core_block_height: None,
57
+ updated_at_core_block_height: None,
58
+ transferred_at_core_block_height: None,
59
+ };
60
+
61
+ let normal_entropy = match entropy {
62
+ Some(entropy) => {
63
+ let mut entropy_sized = [0u8; 32];
64
+ let bytes = entropy.as_slice();
65
+ let len = bytes.len().min(32);
66
+ entropy_sized[..len].copy_from_slice(&bytes[..len]);
67
+ Some(entropy_sized)
68
+ }
69
+ None => None,
70
+ };
71
+
72
+ DocumentBatchWASM {
73
+ batch: batch.clone(),
74
+ document: DocumentWASM::from_batch(
75
+ Document::V0(document),
76
+ data_contract_id,
77
+ document_type_name.to_string(),
78
+ normal_entropy,
79
+ ),
80
+ }
81
+ }
82
+ }
83
+
39
84
  #[wasm_bindgen]
40
85
  impl DocumentBatchWASM {
41
86
  #[wasm_bindgen(js_name=new)]
@@ -110,207 +155,63 @@ impl DocumentBatchWASM {
110
155
  None => wasm_bindgen::throw_str("Entropy is empty"),
111
156
  }
112
157
  }
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
158
 
121
- let sig = st.sign(
122
- &public_key.get_key(),
123
- private_key.get_key().to_bytes().as_slice(),
124
- &MockBLS {},
125
- );
159
+ #[wasm_bindgen(js_name=toStateTransition)]
160
+ pub fn to_state_transition(&self) -> StateTransitionWASM {
161
+ let st = StateTransition::from(self.batch.clone());
126
162
 
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
- };
163
+ StateTransitionWASM::from(st)
164
+ }
165
+
166
+ #[wasm_bindgen(js_name=toBuffer)]
167
+ pub fn to_buffer(&self) -> Result<JsValue, JsValue> {
168
+ let bytes = self.batch.serialize_to_bytes().with_js_error();
136
169
 
137
170
  match bytes {
138
171
  Ok(bytes) => Ok(JsValue::from(bytes.clone())),
139
- Err(e) => Ok(JsValue::from_str(&format!("{}", e))),
172
+ Err(err) => Err(err),
140
173
  }
141
174
  }
142
175
 
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());
176
+ #[wasm_bindgen(js_name=fromStateTransition)]
177
+ pub fn from_state_transition(
178
+ state_transition: StateTransitionWASM,
179
+ ) -> Result<DocumentBatchWASM, JsValue> {
180
+ let rs_st = StateTransition::from(state_transition);
162
181
 
163
- let bytes = st.serialize_to_bytes().with_js_error();
182
+ match rs_st {
183
+ StateTransition::DocumentsBatch(batch) => {
184
+ let transition = batch.transitions().first();
164
185
 
165
- match bytes {
166
- Ok(bytes) => JsValue::from(bytes.clone()),
167
- Err(err) => err,
186
+ match transition {
187
+ None => Err(JsValue::from_str("No transition")),
188
+ Some(document_transition) => Ok(DocumentBatchWASM::from((
189
+ document_transition.clone(),
190
+ batch,
191
+ ))),
192
+ }
193
+ }
194
+ _ => Err(JsValue::from_str("Invalid state transition")),
168
195
  }
169
196
  }
170
197
 
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
198
  pub fn from_buffer(bytes: Vec<u8>) -> Result<DocumentBatchWASM, JsValue> {
182
- let batch = &StateTransition::deserialize_from_bytes(bytes.as_slice()).with_js_error()?;
199
+ let batch_transition =
200
+ DocumentsBatchTransition::deserialize_from_bytes(bytes.as_slice()).with_js_error();
183
201
 
184
- match batch {
185
- StateTransition::DocumentsBatch(batch) => {
202
+ match batch_transition {
203
+ Ok(batch) => {
186
204
  let transition = batch.transitions().first();
187
205
 
188
206
  match transition {
189
207
  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
- }
208
+ Some(document_transition) => Ok(DocumentBatchWASM::from((
209
+ document_transition.clone(),
210
+ batch,
211
+ ))),
311
212
  }
312
213
  }
313
- _ => Err(JsValue::from_str("incorrect batch type")),
214
+ Err(err) => Err(err),
314
215
  }
315
216
  }
316
217
 
@@ -10,4 +10,8 @@ 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
- ]}
13
+ ]}
14
+
15
+ [profile.release]
16
+ lto = true
17
+ opt-level = 'z'
@@ -0,0 +1,17 @@
1
+ [package]
2
+ name = "pshenmic_dpp_identity"
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}
12
+ serde-wasm-bindgen = { git = "https://github.com/QuantumExplorer/serde-wasm-bindgen", branch = "feat/not_human_readable" }
13
+ pshenmic_dpp_public_key = { path = "../public_key" }
14
+
15
+ [profile.release]
16
+ lto = true
17
+ opt-level = 'z'
@@ -0,0 +1,77 @@
1
+ use dpp::identifier::Identifier;
2
+ use dpp::identity::accessors::{IdentityGettersV0, IdentitySettersV0};
3
+ use dpp::identity::{Identity, KeyID};
4
+ use dpp::platform_value::string_encoding::Encoding::Base58;
5
+ use dpp::version::PlatformVersion;
6
+ use pshenmic_dpp_public_key::IdentityPublicKeyWASM;
7
+ use wasm_bindgen::JsValue;
8
+ use wasm_bindgen::prelude::wasm_bindgen;
9
+
10
+ #[wasm_bindgen(js_name = "IdentityWASM")]
11
+ pub struct IdentityWASM(Identity);
12
+
13
+ #[wasm_bindgen]
14
+ impl IdentityWASM {
15
+ #[wasm_bindgen(constructor)]
16
+ pub fn new(js_identifier: String) -> IdentityWASM {
17
+ let identifier = Identifier::from_string(&*js_identifier, Base58);
18
+
19
+ let identity =
20
+ Identity::create_basic_identity(identifier.unwrap(), PlatformVersion::first()).unwrap();
21
+
22
+ IdentityWASM(identity)
23
+ }
24
+
25
+ #[wasm_bindgen(js_name = "setId")]
26
+ pub fn set_id(&mut self, js_identifier: String) {
27
+ let identifier = Identifier::from_string(&*js_identifier, Base58).unwrap();
28
+
29
+ self.0.set_id(identifier);
30
+ }
31
+
32
+ #[wasm_bindgen(js_name = "setBalance")]
33
+ pub fn set_balance(&mut self, balance: u64) {
34
+ self.0.set_balance(balance);
35
+ }
36
+
37
+ #[wasm_bindgen(js_name = "setRevision")]
38
+ pub fn set_revision(&mut self, revision: u64) {
39
+ self.0.set_revision(revision);
40
+ }
41
+
42
+ #[wasm_bindgen(js_name = "addPublicKey")]
43
+ pub fn set_public_key(&mut self, public_key: IdentityPublicKeyWASM) {
44
+ self.0.add_public_key(public_key.into());
45
+ }
46
+
47
+ // GETTERS
48
+
49
+ #[wasm_bindgen(js_name = "getId")]
50
+ pub fn get_id(&self) -> String {
51
+ let id = self.0.id();
52
+
53
+ id.to_string(Base58)
54
+ }
55
+
56
+ #[wasm_bindgen(js_name = "getBalance")]
57
+ pub fn get_balance(&self) -> u64 {
58
+ self.0.balance()
59
+ }
60
+
61
+ #[wasm_bindgen(js_name = "getRevision")]
62
+ pub fn get_revision(&self) -> u64 {
63
+ self.0.revision()
64
+ }
65
+
66
+ #[wasm_bindgen(js_name = "getPublicKeyById")]
67
+ pub fn get_public_key_by_id(&self, key_id: KeyID) -> IdentityPublicKeyWASM {
68
+ let identity_public_key = self.0.get_public_key_by_id(key_id);
69
+ IdentityPublicKeyWASM::from(identity_public_key.unwrap().clone())
70
+ }
71
+
72
+ #[wasm_bindgen(js_name = "getPublicKeys")]
73
+ pub fn get_public_keys(&self) -> JsValue {
74
+ let keys = self.0.public_keys();
75
+ serde_wasm_bindgen::to_value(keys).unwrap()
76
+ }
77
+ }
@@ -0,0 +1,21 @@
1
+ [package]
2
+ name = "pshenmic_dpp_identity_transitions"
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
+ "state-transition-signing"
13
+ ]}
14
+ pshenmic_dpp_utils = {path = "../utils"}
15
+ pshenmic_dpp_public_key = {path = "../public_key"}
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'
@@ -0,0 +1,99 @@
1
+ mod public_key_in_creation;
2
+
3
+ use dpp::platform_value::string_encoding::Encoding::Base58;
4
+ use dpp::serialization::{PlatformDeserializable, PlatformSerializable};
5
+ use dpp::state_transition::identity_create_transition::IdentityCreateTransition;
6
+ use dpp::state_transition::identity_create_transition::accessors::IdentityCreateTransitionAccessorsV0;
7
+ use dpp::state_transition::{StateTransition, StateTransitionLike};
8
+ use dpp::version::PlatformVersion;
9
+ use pshenmic_dpp_state_transition::StateTransitionWASM;
10
+ use pshenmic_dpp_utils::WithJsError;
11
+ use public_key_in_creation::IdentityPublicKeyInCreationWASM;
12
+ use wasm_bindgen::JsValue;
13
+ use wasm_bindgen::prelude::wasm_bindgen;
14
+
15
+ #[wasm_bindgen(js_name = IdentityCreateTransitionWASM)]
16
+ #[derive(Clone)]
17
+ pub struct IdentityCreateTransitionWASM(IdentityCreateTransition);
18
+
19
+ impl From<IdentityCreateTransition> for IdentityCreateTransitionWASM {
20
+ fn from(val: IdentityCreateTransition) -> Self {
21
+ IdentityCreateTransitionWASM(val)
22
+ }
23
+ }
24
+
25
+ impl From<IdentityCreateTransitionWASM> for IdentityCreateTransition {
26
+ fn from(val: IdentityCreateTransitionWASM) -> Self {
27
+ val.0
28
+ }
29
+ }
30
+
31
+ #[wasm_bindgen]
32
+ impl IdentityCreateTransitionWASM {
33
+ #[wasm_bindgen(constructor)]
34
+ pub fn new(platform_version: u32) -> Result<IdentityCreateTransitionWASM, JsValue> {
35
+ let platform_version =
36
+ &PlatformVersion::get(platform_version).map_err(|e| JsValue::from(e.to_string()))?;
37
+
38
+ IdentityCreateTransition::default_versioned(platform_version)
39
+ .map(Into::into)
40
+ .map_err(|err| JsValue::from_str(&*err.to_string()))
41
+ }
42
+
43
+ #[wasm_bindgen(js_name = "defaultVersioned")]
44
+ pub fn get_public_keys(&self) -> Vec<IdentityPublicKeyInCreationWASM> {
45
+ self.0
46
+ .public_keys()
47
+ .iter()
48
+ .map(|key| IdentityPublicKeyInCreationWASM::from(key.clone()))
49
+ .collect()
50
+ }
51
+
52
+ #[wasm_bindgen(js_name = "getIdentifier")]
53
+ pub fn get_identity_id(&self) -> String {
54
+ self.0.identity_id().to_string(Base58)
55
+ }
56
+
57
+ #[wasm_bindgen(js_name = "getUserFeeIncrease")]
58
+ pub fn get_user_fee_increase(&self) -> u16 {
59
+ self.0.user_fee_increase()
60
+ }
61
+
62
+ #[wasm_bindgen(js_name = "toStateTransition")]
63
+ pub fn to_state_transition(&self) -> StateTransitionWASM {
64
+ StateTransitionWASM::from(StateTransition::IdentityCreate(self.clone().0))
65
+ }
66
+
67
+ #[wasm_bindgen(js_name = "toBuffer")]
68
+ pub fn to_buffer(&self) -> Result<JsValue, JsValue> {
69
+ let bytes = self.0.serialize_to_bytes().with_js_error();
70
+
71
+ match bytes {
72
+ Ok(bytes) => Ok(JsValue::from(bytes.clone())),
73
+ Err(err) => Err(err),
74
+ }
75
+ }
76
+
77
+ #[wasm_bindgen(js_name = "fromStateTransition")]
78
+ pub fn from_state_transition(
79
+ st: StateTransitionWASM,
80
+ ) -> Result<IdentityCreateTransitionWASM, JsValue> {
81
+ let rs_st: StateTransition = st.into();
82
+
83
+ match rs_st {
84
+ StateTransition::IdentityCreate(st) => Ok(IdentityCreateTransitionWASM(st)),
85
+ _ => Err(JsValue::from_str(&"Invalid state transition type)")),
86
+ }
87
+ }
88
+
89
+ #[wasm_bindgen(js_name = "fromBuffer")]
90
+ pub fn from_buffer(bytes: Vec<u8>) -> Result<IdentityCreateTransitionWASM, JsValue> {
91
+ let rs_transition =
92
+ IdentityCreateTransition::deserialize_from_bytes(bytes.as_slice()).with_js_error();
93
+
94
+ match rs_transition {
95
+ Ok(rs_st) => Ok(IdentityCreateTransitionWASM(rs_st)),
96
+ Err(err) => Err(err),
97
+ }
98
+ }
99
+ }