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.
- package/.github/workflows/build.yml +1 -1
- package/.github/workflows/publish.yml +1 -1
- package/Cargo.lock +147 -49
- package/Cargo.toml +13 -7
- package/README.md +10 -1
- package/dist/wasm/index.d.ts +52 -0
- package/dist/wasm/pshenmic_dpp.d.ts +962 -0
- package/dist/wasm/pshenmic_dpp.js +3342 -875
- package/dist/wasm/pshenmic_dpp_bg.js +1 -1
- package/dist/wasm/pshenmic_dpp_bg.wasm.d.ts +440 -0
- package/docs/AssetLockProof.md +107 -0
- package/docs/Building.md +50 -0
- package/docs/ChainLockProof.md +63 -0
- package/docs/CoreScript.md +17 -0
- package/docs/DataContract.md +192 -0
- package/docs/DataContractCreateTransition.md +84 -0
- package/docs/DataContractUpdateTransition.md +84 -0
- package/docs/Document.md +396 -0
- package/docs/DocumentBaseTransition.md +111 -0
- package/docs/DocumentCreateTransition.md +132 -0
- package/docs/DocumentDeleteTransition.md +82 -0
- package/docs/DocumentPurchaseTransition.md +109 -0
- package/docs/DocumentReplaceTransition.md +112 -0
- package/docs/DocumentTransferTransition.md +96 -0
- package/docs/DocumentTransition.md +125 -0
- package/docs/DocumentUpdatePriceTransition.md +109 -0
- package/docs/DocumentsBatch.md +133 -0
- package/docs/Enums.md +103 -0
- package/docs/Home.md +28 -0
- package/docs/Identifier.md +37 -0
- package/docs/Identity.md +140 -0
- package/docs/IdentityCreateTransition.md +155 -0
- package/docs/IdentityCreditTransfer.md +187 -0
- package/docs/IdentityCreditWithdrawalTransition.md +244 -0
- package/docs/IdentityPublicKey.md +348 -0
- package/docs/IdentityPublicKeyInCreation.md +141 -0
- package/docs/IdentityTopUpTransition.md +166 -0
- package/docs/IdentityUpdateTransition.md +234 -0
- package/docs/InstantAssetLockProof.md +117 -0
- package/docs/InstantLock.md +100 -0
- package/docs/OutPoint.md +80 -0
- package/docs/PrefundedVotingBalance.md +48 -0
- package/docs/PrivateKey.md +112 -0
- package/docs/TxOut.md +93 -0
- package/package.json +3 -3
- package/packages/asset_lock_proof/Cargo.toml +19 -0
- package/packages/asset_lock_proof/src/chain/mod.rs +79 -0
- package/packages/asset_lock_proof/src/instant/instant_lock.rs +111 -0
- package/packages/asset_lock_proof/src/instant/mod.rs +115 -0
- package/packages/asset_lock_proof/src/lib.rs +133 -0
- package/packages/asset_lock_proof/src/outpoint/mod.rs +79 -0
- package/packages/asset_lock_proof/src/tx_out/mod.rs +80 -0
- package/packages/cbor_conversation/Cargo.toml +1 -1
- package/packages/core_script/Cargo.toml +13 -0
- package/packages/core_script/src/lib.rs +69 -0
- package/packages/data_contract/Cargo.toml +2 -1
- package/packages/data_contract/src/lib.rs +34 -30
- package/packages/data_contract_transitions/Cargo.toml +1 -1
- package/packages/data_contract_transitions/src/create/mod.rs +3 -3
- package/packages/data_contract_transitions/src/update/mod.rs +3 -3
- package/packages/document/Cargo.toml +2 -1
- package/packages/document/src/lib.rs +13 -12
- package/packages/document/src/methods/mod.rs +41 -38
- package/packages/documents_batch/Cargo.toml +2 -1
- package/packages/documents_batch/src/document_base_transition/mod.rs +16 -20
- package/packages/documents_batch/src/document_transition/mod.rs +9 -9
- package/packages/documents_batch/src/lib.rs +23 -16
- package/packages/documents_batch/src/transitions/create/mod.rs +5 -2
- package/packages/documents_batch/src/transitions/transfer/mod.rs +9 -11
- package/packages/enums/Cargo.toml +1 -1
- package/packages/enums/src/batch/batch_enum.rs +2 -2
- package/packages/enums/src/lib.rs +2 -0
- package/packages/enums/src/lock_types/mod.rs +65 -0
- package/packages/enums/src/platform/mod.rs +2 -0
- package/packages/enums/src/withdrawal/mod.rs +72 -0
- package/packages/identifier/Cargo.toml +9 -0
- package/packages/identifier/src/lib.rs +105 -0
- package/packages/identity/Cargo.toml +2 -1
- package/packages/identity/src/lib.rs +13 -18
- package/packages/identity_public_key/Cargo.toml +1 -1
- package/packages/identity_transitions/Cargo.toml +7 -3
- package/packages/identity_transitions/src/create_transition/mod.rs +99 -36
- package/packages/identity_transitions/src/credit_withdrawal_transition/mod.rs +212 -0
- package/packages/identity_transitions/src/identity_credit_transfer_transition/mod.rs +169 -0
- package/packages/identity_transitions/src/lib.rs +6 -1
- package/packages/identity_transitions/src/{create_transition/public_key_in_creation → public_key_in_creation}/mod.rs +67 -20
- package/packages/identity_transitions/src/top_up_transition/mod.rs +141 -0
- package/packages/identity_transitions/src/update_transition/mod.rs +213 -0
- package/packages/private_key/Cargo.toml +1 -1
- package/packages/state_transition/Cargo.toml +2 -1
- package/packages/state_transition/src/lib.rs +3 -2
- package/packages/utils/Cargo.toml +2 -2
- package/packages/utils/src/lib.rs +0 -3
- package/scripts/build-js.sh +16 -0
- package/scripts/build.sh +5 -1
- package/src/lib.rs +1 -0
- package/tests/AssetLockProof.spec.js +80 -0
- package/tests/ChainLockProof.spec.js +69 -0
- package/tests/CoreScript.spec.js +37 -0
- package/tests/DataContract.spec.js +17 -14
- package/tests/Document.spec.js +14 -8
- package/tests/DocumentBatchTransition.spec.js +11 -11
- package/tests/DocumentTransition.spec.js +4 -4
- package/tests/DocumentsTransitions.spec.js +22 -22
- package/tests/Identifier.spec.js +84 -0
- package/tests/Identity.spec.js +1 -1
- package/tests/IdentityCreateTransition.spec.js +93 -0
- package/tests/IdentityCreditTransferTransition.spec.js +146 -0
- package/tests/IdentityCreditWithdrawalTransition.spec.js +192 -0
- package/tests/IdentityTopUpTransition.spec.js +131 -0
- package/tests/IdentityUpdateTransition.spec.js +147 -0
- package/tests/InstantLockProof.spec.js +97 -0
- package/tests/OutPoint.spec.js +55 -0
- package/tests/PublicKeyInCreation.spec.js +258 -0
- package/tests/TxOut.spec.js +76 -0
- package/tests/mocks/Locks/index.js +5 -0
- package/tests/mocks/PublicKey/index.js +1 -1
- package/typings/index.d.ts +52 -0
|
@@ -5,16 +5,17 @@ use dpp::identifier::Identifier;
|
|
|
5
5
|
use dpp::identity::TimestampMillis;
|
|
6
6
|
use dpp::platform_value::Value;
|
|
7
7
|
use dpp::prelude::{BlockHeight, CoreBlockHeight, Revision};
|
|
8
|
+
use pshenmic_dpp_identifier::IdentifierWASM;
|
|
8
9
|
use std::collections::BTreeMap;
|
|
9
10
|
use wasm_bindgen::prelude::wasm_bindgen;
|
|
10
11
|
|
|
11
|
-
#[derive(
|
|
12
|
+
#[derive(Clone)]
|
|
12
13
|
#[wasm_bindgen(js_name = DocumentWASM)]
|
|
13
14
|
pub struct DocumentWASM {
|
|
14
|
-
id:
|
|
15
|
-
owner_id:
|
|
15
|
+
id: IdentifierWASM,
|
|
16
|
+
owner_id: IdentifierWASM,
|
|
16
17
|
revision: Option<Revision>,
|
|
17
|
-
data_contract_id:
|
|
18
|
+
data_contract_id: IdentifierWASM,
|
|
18
19
|
document_type_name: String,
|
|
19
20
|
properties: BTreeMap<String, Value>,
|
|
20
21
|
created_at: Option<TimestampMillis>,
|
|
@@ -32,8 +33,8 @@ pub struct DocumentWASM {
|
|
|
32
33
|
impl From<DocumentWASM> for Document {
|
|
33
34
|
fn from(wasm_doc: DocumentWASM) -> Self {
|
|
34
35
|
Document::V0(DocumentV0 {
|
|
35
|
-
id: wasm_doc.id,
|
|
36
|
-
owner_id: wasm_doc.owner_id,
|
|
36
|
+
id: wasm_doc.id.into(),
|
|
37
|
+
owner_id: wasm_doc.owner_id.into(),
|
|
37
38
|
properties: wasm_doc.properties,
|
|
38
39
|
revision: wasm_doc.revision,
|
|
39
40
|
created_at: wasm_doc.created_at,
|
|
@@ -52,10 +53,10 @@ impl From<DocumentWASM> for Document {
|
|
|
52
53
|
impl From<Document> for DocumentWASM {
|
|
53
54
|
fn from(doc: Document) -> Self {
|
|
54
55
|
DocumentWASM {
|
|
55
|
-
id: doc.id(),
|
|
56
|
-
owner_id: doc.owner_id(),
|
|
56
|
+
id: doc.id().into(),
|
|
57
|
+
owner_id: doc.owner_id().into(),
|
|
57
58
|
revision: doc.revision(),
|
|
58
|
-
data_contract_id:
|
|
59
|
+
data_contract_id: Identifier::default().into(),
|
|
59
60
|
document_type_name: "".to_string(),
|
|
60
61
|
properties: doc.properties().clone(),
|
|
61
62
|
created_at: doc.created_at(),
|
|
@@ -80,10 +81,10 @@ impl DocumentWASM {
|
|
|
80
81
|
entropy: Option<[u8; 32]>,
|
|
81
82
|
) -> Self {
|
|
82
83
|
DocumentWASM {
|
|
83
|
-
id: document.id(),
|
|
84
|
-
owner_id: document.owner_id(),
|
|
84
|
+
id: document.id().into(),
|
|
85
|
+
owner_id: document.owner_id().into(),
|
|
85
86
|
revision: document.revision(),
|
|
86
|
-
data_contract_id,
|
|
87
|
+
data_contract_id: data_contract_id.into(),
|
|
87
88
|
document_type_name,
|
|
88
89
|
properties: document.properties().clone(),
|
|
89
90
|
created_at: document.created_at(),
|
|
@@ -12,7 +12,8 @@ use dpp::util::entropy_generator;
|
|
|
12
12
|
use dpp::util::entropy_generator::EntropyGenerator;
|
|
13
13
|
use pshenmic_dpp_data_contract::DataContractWASM;
|
|
14
14
|
use pshenmic_dpp_enums::platform::PlatformVersionWASM;
|
|
15
|
-
use
|
|
15
|
+
use pshenmic_dpp_identifier::IdentifierWASM;
|
|
16
|
+
use pshenmic_dpp_utils::{ToSerdeJSONExt, WithJsError};
|
|
16
17
|
use std::collections::BTreeMap;
|
|
17
18
|
use wasm_bindgen::JsValue;
|
|
18
19
|
use wasm_bindgen::prelude::wasm_bindgen;
|
|
@@ -24,36 +25,35 @@ impl DocumentWASM {
|
|
|
24
25
|
js_raw_document: JsValue,
|
|
25
26
|
js_document_type_name: &str,
|
|
26
27
|
js_revision: u64,
|
|
27
|
-
js_data_contract_id: JsValue,
|
|
28
|
-
js_owner_id: JsValue,
|
|
28
|
+
js_data_contract_id: &JsValue,
|
|
29
|
+
js_owner_id: &JsValue,
|
|
29
30
|
js_document_id: JsValue,
|
|
30
31
|
) -> Result<DocumentWASM, JsValue> {
|
|
32
|
+
let data_contract_id = IdentifierWASM::try_from(js_data_contract_id)?;
|
|
33
|
+
let owner_id = IdentifierWASM::try_from(js_owner_id)?;
|
|
34
|
+
|
|
31
35
|
let revision = Revision::from(js_revision);
|
|
32
36
|
|
|
33
37
|
let document = js_raw_document
|
|
34
38
|
.with_serde_to_platform_value_map()
|
|
35
39
|
.expect("cannot convert document to platform value map");
|
|
36
40
|
|
|
37
|
-
let owner_id = identifier_from_js_value(&js_owner_id)?;
|
|
38
|
-
let data_contract_id = identifier_from_js_value(&js_data_contract_id)?;
|
|
39
41
|
let revision = Revision::from(revision);
|
|
40
42
|
|
|
41
43
|
let entropy = entropy_generator::DefaultEntropyGenerator
|
|
42
44
|
.generate()
|
|
43
45
|
.unwrap();
|
|
44
46
|
|
|
45
|
-
let document_id:
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
}?;
|
|
47
|
+
let document_id: IdentifierWASM = match js_document_id.is_undefined() {
|
|
48
|
+
true => pshenmic_dpp_utils::generate_document_id_v0(
|
|
49
|
+
&data_contract_id.into(),
|
|
50
|
+
&owner_id.into(),
|
|
51
|
+
js_document_type_name,
|
|
52
|
+
&entropy,
|
|
53
|
+
)?
|
|
54
|
+
.into(),
|
|
55
|
+
false => js_document_id.try_into()?,
|
|
56
|
+
};
|
|
57
57
|
|
|
58
58
|
Ok(DocumentWASM {
|
|
59
59
|
owner_id,
|
|
@@ -76,8 +76,8 @@ impl DocumentWASM {
|
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
#[wasm_bindgen(js_name=getId)]
|
|
79
|
-
pub fn get_id(&self) ->
|
|
80
|
-
self.id
|
|
79
|
+
pub fn get_id(&self) -> IdentifierWASM {
|
|
80
|
+
self.id
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
#[wasm_bindgen(js_name=getEntropy)]
|
|
@@ -89,13 +89,13 @@ impl DocumentWASM {
|
|
|
89
89
|
}
|
|
90
90
|
|
|
91
91
|
#[wasm_bindgen(js_name=getDataContractId)]
|
|
92
|
-
pub fn get_data_contract_id(&self) ->
|
|
93
|
-
self.data_contract_id
|
|
92
|
+
pub fn get_data_contract_id(&self) -> IdentifierWASM {
|
|
93
|
+
self.data_contract_id
|
|
94
94
|
}
|
|
95
95
|
|
|
96
96
|
#[wasm_bindgen(js_name=getOwnerId)]
|
|
97
|
-
pub fn get_owner_id(&self) ->
|
|
98
|
-
self.owner_id
|
|
97
|
+
pub fn get_owner_id(&self) -> IdentifierWASM {
|
|
98
|
+
self.owner_id
|
|
99
99
|
}
|
|
100
100
|
|
|
101
101
|
#[wasm_bindgen(js_name=getProperties)]
|
|
@@ -167,8 +167,9 @@ impl DocumentWASM {
|
|
|
167
167
|
}
|
|
168
168
|
|
|
169
169
|
#[wasm_bindgen(js_name=setId)]
|
|
170
|
-
pub fn set_id(&mut self, id: JsValue) {
|
|
171
|
-
self.id =
|
|
170
|
+
pub fn set_id(&mut self, id: &JsValue) -> Result<(), JsValue> {
|
|
171
|
+
self.id = IdentifierWASM::try_from(id)?.clone();
|
|
172
|
+
Ok(())
|
|
172
173
|
}
|
|
173
174
|
|
|
174
175
|
#[wasm_bindgen(js_name=setEntropy)]
|
|
@@ -188,8 +189,9 @@ impl DocumentWASM {
|
|
|
188
189
|
}
|
|
189
190
|
|
|
190
191
|
#[wasm_bindgen(js_name=setOwnerId)]
|
|
191
|
-
pub fn set_owner_id(&mut self, id: JsValue) {
|
|
192
|
-
self.owner_id =
|
|
192
|
+
pub fn set_owner_id(&mut self, id: &JsValue) -> Result<(), JsValue> {
|
|
193
|
+
self.owner_id = IdentifierWASM::try_from(id)?.clone();
|
|
194
|
+
Ok(())
|
|
193
195
|
}
|
|
194
196
|
|
|
195
197
|
#[wasm_bindgen(js_name=setProperties)]
|
|
@@ -263,7 +265,7 @@ impl DocumentWASM {
|
|
|
263
265
|
js_platform_version: JsValue,
|
|
264
266
|
) -> Result<Vec<u8>, JsValue> {
|
|
265
267
|
let platform_version = match js_platform_version.is_undefined() {
|
|
266
|
-
true => PlatformVersionWASM::
|
|
268
|
+
true => PlatformVersionWASM::default(),
|
|
267
269
|
false => PlatformVersionWASM::try_from(js_platform_version)?,
|
|
268
270
|
};
|
|
269
271
|
|
|
@@ -289,7 +291,7 @@ impl DocumentWASM {
|
|
|
289
291
|
js_platform_version: JsValue,
|
|
290
292
|
) -> Result<DocumentWASM, JsValue> {
|
|
291
293
|
let platform_version = match js_platform_version.is_undefined() {
|
|
292
|
-
true => PlatformVersionWASM::
|
|
294
|
+
true => PlatformVersionWASM::default(),
|
|
293
295
|
false => PlatformVersionWASM::try_from(js_platform_version)?,
|
|
294
296
|
};
|
|
295
297
|
|
|
@@ -314,12 +316,13 @@ impl DocumentWASM {
|
|
|
314
316
|
#[wasm_bindgen(js_name=generateId)]
|
|
315
317
|
pub fn generate_id(
|
|
316
318
|
js_document_type_name: &str,
|
|
317
|
-
js_owner_id: JsValue,
|
|
318
|
-
js_data_contract_id: JsValue,
|
|
319
|
+
js_owner_id: &JsValue,
|
|
320
|
+
js_data_contract_id: &JsValue,
|
|
319
321
|
opt_entropy: Option<Vec<u8>>,
|
|
320
322
|
) -> Result<Vec<u8>, JsValue> {
|
|
321
|
-
let owner_id =
|
|
322
|
-
let data_contract_id =
|
|
323
|
+
let owner_id = IdentifierWASM::try_from(js_owner_id)?;
|
|
324
|
+
let data_contract_id = IdentifierWASM::try_from(js_data_contract_id)?;
|
|
325
|
+
|
|
323
326
|
let entropy: [u8; 32] = match opt_entropy {
|
|
324
327
|
Some(entropy_vec) => {
|
|
325
328
|
let mut entropy = [0u8; 32];
|
|
@@ -334,8 +337,8 @@ impl DocumentWASM {
|
|
|
334
337
|
};
|
|
335
338
|
|
|
336
339
|
let identifier = pshenmic_dpp_utils::generate_document_id_v0(
|
|
337
|
-
&data_contract_id,
|
|
338
|
-
&owner_id,
|
|
340
|
+
&data_contract_id.into(),
|
|
341
|
+
&owner_id.into(),
|
|
339
342
|
js_document_type_name,
|
|
340
343
|
&entropy,
|
|
341
344
|
);
|
|
@@ -349,15 +352,15 @@ impl DocumentWASM {
|
|
|
349
352
|
|
|
350
353
|
impl DocumentWASM {
|
|
351
354
|
pub fn rs_get_owner_id(&self) -> Identifier {
|
|
352
|
-
self.owner_id
|
|
355
|
+
self.owner_id.into()
|
|
353
356
|
}
|
|
354
357
|
|
|
355
358
|
pub fn rs_get_id(&self) -> Identifier {
|
|
356
|
-
self.id
|
|
359
|
+
self.id.into()
|
|
357
360
|
}
|
|
358
361
|
|
|
359
362
|
pub fn rs_get_data_contract_id(&self) -> Identifier {
|
|
360
|
-
self.data_contract_id
|
|
363
|
+
self.data_contract_id.into()
|
|
361
364
|
}
|
|
362
365
|
|
|
363
366
|
pub fn rs_get_entropy(&self) -> Option<[u8; 32]> {
|
|
@@ -10,10 +10,11 @@ crate-type = ["cdylib", "lib"]
|
|
|
10
10
|
wasm-bindgen = { version = "=0.2.100", default-features = false, features = ["serde-serialize"] }
|
|
11
11
|
pshenmic_dpp_document = {path = "../document"}
|
|
12
12
|
pshenmic_dpp_enums = {path = "../enums"}
|
|
13
|
+
pshenmic_dpp_identifier = {path = "../identifier"}
|
|
13
14
|
pshenmic_dpp_utils = {path = "../utils"}
|
|
14
15
|
pshenmic_dpp_state_transition = {path = "../state_transition"}
|
|
15
16
|
dpp = { git = "https://github.com/dashpay/platform", branch = "master", default-features = false, features = [
|
|
16
17
|
"document-json-conversion",
|
|
17
18
|
]}
|
|
18
|
-
js-sys = "0.3.
|
|
19
|
+
js-sys = "0.3.53"
|
|
19
20
|
serde-wasm-bindgen = { git = "https://github.com/QuantumExplorer/serde-wasm-bindgen", branch = "feat/not_human_readable" }
|
|
@@ -2,7 +2,7 @@ use dpp::prelude::IdentityNonce;
|
|
|
2
2
|
use dpp::state_transition::documents_batch_transition::document_base_transition::DocumentBaseTransition;
|
|
3
3
|
use dpp::state_transition::documents_batch_transition::document_base_transition::v0::DocumentBaseTransitionV0;
|
|
4
4
|
use dpp::state_transition::documents_batch_transition::document_base_transition::v0::v0_methods::DocumentBaseTransitionV0Methods;
|
|
5
|
-
use
|
|
5
|
+
use pshenmic_dpp_identifier::IdentifierWASM;
|
|
6
6
|
use wasm_bindgen::JsValue;
|
|
7
7
|
use wasm_bindgen::prelude::wasm_bindgen;
|
|
8
8
|
|
|
@@ -26,19 +26,16 @@ impl From<DocumentBaseTransitionWASM> for DocumentBaseTransition {
|
|
|
26
26
|
impl DocumentBaseTransitionWASM {
|
|
27
27
|
#[wasm_bindgen(constructor)]
|
|
28
28
|
pub fn new(
|
|
29
|
-
js_document_id: JsValue,
|
|
29
|
+
js_document_id: &JsValue,
|
|
30
30
|
identity_contract_nonce: IdentityNonce,
|
|
31
31
|
document_type_name: String,
|
|
32
|
-
js_data_contract_id: JsValue,
|
|
32
|
+
js_data_contract_id: &JsValue,
|
|
33
33
|
) -> Result<DocumentBaseTransitionWASM, JsValue> {
|
|
34
|
-
let document_id = identifier_from_js_value(&js_document_id)?;
|
|
35
|
-
let data_contract_id = identifier_from_js_value(&js_data_contract_id)?;
|
|
36
|
-
|
|
37
34
|
let rs_base_v0 = DocumentBaseTransitionV0 {
|
|
38
|
-
id:
|
|
35
|
+
id: IdentifierWASM::try_from(js_document_id)?.into(),
|
|
39
36
|
identity_contract_nonce,
|
|
40
37
|
document_type_name,
|
|
41
|
-
data_contract_id,
|
|
38
|
+
data_contract_id: IdentifierWASM::try_from(js_data_contract_id)?.into(),
|
|
42
39
|
};
|
|
43
40
|
|
|
44
41
|
Ok(DocumentBaseTransitionWASM(DocumentBaseTransition::from(
|
|
@@ -47,8 +44,8 @@ impl DocumentBaseTransitionWASM {
|
|
|
47
44
|
}
|
|
48
45
|
|
|
49
46
|
#[wasm_bindgen(getter = "id")]
|
|
50
|
-
pub fn get_id(&self) ->
|
|
51
|
-
self.0.id().
|
|
47
|
+
pub fn get_id(&self) -> IdentifierWASM {
|
|
48
|
+
self.0.id().into()
|
|
52
49
|
}
|
|
53
50
|
|
|
54
51
|
#[wasm_bindgen(getter = "identityContractNonce")]
|
|
@@ -57,8 +54,8 @@ impl DocumentBaseTransitionWASM {
|
|
|
57
54
|
}
|
|
58
55
|
|
|
59
56
|
#[wasm_bindgen(getter = "dataContractId")]
|
|
60
|
-
pub fn get_data_contract_id(&self) ->
|
|
61
|
-
self.0.data_contract_id().
|
|
57
|
+
pub fn get_data_contract_id(&self) -> IdentifierWASM {
|
|
58
|
+
self.0.data_contract_id().into()
|
|
62
59
|
}
|
|
63
60
|
|
|
64
61
|
#[wasm_bindgen(getter = "documentTypeName")]
|
|
@@ -67,10 +64,9 @@ impl DocumentBaseTransitionWASM {
|
|
|
67
64
|
}
|
|
68
65
|
|
|
69
66
|
#[wasm_bindgen(setter = "id")]
|
|
70
|
-
pub fn set_id(&mut self, js_id: JsValue) -> Result<(), JsValue> {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
Ok(self.0.set_id(id))
|
|
67
|
+
pub fn set_id(&mut self, js_id: &JsValue) -> Result<(), JsValue> {
|
|
68
|
+
self.0.set_id(IdentifierWASM::try_from(js_id)?.into());
|
|
69
|
+
Ok(())
|
|
74
70
|
}
|
|
75
71
|
|
|
76
72
|
#[wasm_bindgen(setter = "identityContractNonce")]
|
|
@@ -79,10 +75,10 @@ impl DocumentBaseTransitionWASM {
|
|
|
79
75
|
}
|
|
80
76
|
|
|
81
77
|
#[wasm_bindgen(setter = "dataContractId")]
|
|
82
|
-
pub fn set_data_contract_id(&mut self, js_data_contract_id: JsValue) -> Result<(), JsValue> {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
Ok(
|
|
78
|
+
pub fn set_data_contract_id(&mut self, js_data_contract_id: &JsValue) -> Result<(), JsValue> {
|
|
79
|
+
self.0
|
|
80
|
+
.set_data_contract_id(IdentifierWASM::try_from(js_data_contract_id)?.into());
|
|
81
|
+
Ok(())
|
|
86
82
|
}
|
|
87
83
|
|
|
88
84
|
#[wasm_bindgen(setter = "documentTypeName")]
|
|
@@ -10,7 +10,7 @@ use dpp::state_transition::documents_batch_transition::document_transition::{
|
|
|
10
10
|
DocumentTransition, DocumentTransitionV0Methods,
|
|
11
11
|
};
|
|
12
12
|
use pshenmic_dpp_enums::batch::batch_enum::BatchTypeWASM;
|
|
13
|
-
use
|
|
13
|
+
use pshenmic_dpp_identifier::IdentifierWASM;
|
|
14
14
|
use wasm_bindgen::JsValue;
|
|
15
15
|
use wasm_bindgen::prelude::wasm_bindgen;
|
|
16
16
|
|
|
@@ -38,13 +38,13 @@ impl DocumentTransitionWASM {
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
#[wasm_bindgen(getter = "dataContractId")]
|
|
41
|
-
pub fn get_data_contract_id(&self) ->
|
|
42
|
-
self.0.data_contract_id().
|
|
41
|
+
pub fn get_data_contract_id(&self) -> IdentifierWASM {
|
|
42
|
+
self.0.data_contract_id().into()
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
#[wasm_bindgen(getter = "id")]
|
|
46
|
-
pub fn get_id(&self) ->
|
|
47
|
-
self.0.get_id().
|
|
46
|
+
pub fn get_id(&self) -> IdentifierWASM {
|
|
47
|
+
self.0.get_id().into()
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
#[wasm_bindgen(getter = "documentTypeName")]
|
|
@@ -126,10 +126,10 @@ impl DocumentTransitionWASM {
|
|
|
126
126
|
}
|
|
127
127
|
|
|
128
128
|
#[wasm_bindgen(setter = "dataContractId")]
|
|
129
|
-
pub fn set_data_contract_id(&mut self, js_data_contract_id: JsValue) -> Result<(), JsValue> {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
129
|
+
pub fn set_data_contract_id(&mut self, js_data_contract_id: &JsValue) -> Result<(), JsValue> {
|
|
130
|
+
Ok(self
|
|
131
|
+
.0
|
|
132
|
+
.set_data_contract_id(IdentifierWASM::try_from(js_data_contract_id)?.into()))
|
|
133
133
|
}
|
|
134
134
|
|
|
135
135
|
#[wasm_bindgen(setter = "revision")]
|
|
@@ -11,8 +11,9 @@ use dpp::state_transition::documents_batch_transition::{
|
|
|
11
11
|
DocumentsBatchTransition, DocumentsBatchTransitionV0,
|
|
12
12
|
};
|
|
13
13
|
use dpp::state_transition::{StateTransition, StateTransitionIdentitySigned, StateTransitionLike};
|
|
14
|
+
use pshenmic_dpp_identifier::IdentifierWASM;
|
|
14
15
|
use pshenmic_dpp_state_transition::StateTransitionWASM;
|
|
15
|
-
use pshenmic_dpp_utils::{IntoWasm, WithJsError
|
|
16
|
+
use pshenmic_dpp_utils::{IntoWasm, WithJsError};
|
|
16
17
|
use wasm_bindgen::JsValue;
|
|
17
18
|
use wasm_bindgen::prelude::wasm_bindgen;
|
|
18
19
|
|
|
@@ -42,15 +43,16 @@ impl From<DocumentsBatchWASM> for DocumentsBatchTransition {
|
|
|
42
43
|
impl DocumentsBatchWASM {
|
|
43
44
|
#[wasm_bindgen(constructor)]
|
|
44
45
|
pub fn new(
|
|
45
|
-
document_transitions: js_sys::Array,
|
|
46
|
-
js_owner_id: JsValue,
|
|
46
|
+
document_transitions: &js_sys::Array,
|
|
47
|
+
js_owner_id: &JsValue,
|
|
47
48
|
user_fee_increase: Option<UserFeeIncrease>,
|
|
48
49
|
signature_public_key_id: Option<KeyID>,
|
|
49
50
|
signature: Option<Vec<u8>>,
|
|
50
51
|
) -> Result<DocumentsBatchWASM, JsValue> {
|
|
51
|
-
let owner_id =
|
|
52
|
+
let owner_id = IdentifierWASM::try_from(js_owner_id)?;
|
|
52
53
|
|
|
53
54
|
let transitions: Vec<DocumentTransition> = document_transitions
|
|
55
|
+
.clone()
|
|
54
56
|
.iter()
|
|
55
57
|
.map(|js_document_transition| {
|
|
56
58
|
let document_transition: DocumentTransitionWASM = js_document_transition
|
|
@@ -64,7 +66,7 @@ impl DocumentsBatchWASM {
|
|
|
64
66
|
|
|
65
67
|
Ok(DocumentsBatchWASM(DocumentsBatchTransition::V0(
|
|
66
68
|
DocumentsBatchTransitionV0 {
|
|
67
|
-
owner_id,
|
|
69
|
+
owner_id: owner_id.into(),
|
|
68
70
|
transitions,
|
|
69
71
|
user_fee_increase: user_fee_increase.unwrap_or(0),
|
|
70
72
|
signature_public_key_id: signature_public_key_id.unwrap_or(0),
|
|
@@ -99,20 +101,17 @@ impl DocumentsBatchWASM {
|
|
|
99
101
|
}
|
|
100
102
|
|
|
101
103
|
#[wasm_bindgen(getter = "ownerId")]
|
|
102
|
-
pub fn get_owner_id(&self) ->
|
|
103
|
-
self.0.owner_id().
|
|
104
|
+
pub fn get_owner_id(&self) -> IdentifierWASM {
|
|
105
|
+
self.0.owner_id().into()
|
|
104
106
|
}
|
|
105
107
|
|
|
106
108
|
#[wasm_bindgen(getter = "modifiedDataIds")]
|
|
107
|
-
pub fn get_modified_data_ids(&self) ->
|
|
108
|
-
|
|
109
|
-
.0
|
|
109
|
+
pub fn get_modified_data_ids(&self) -> Vec<IdentifierWASM> {
|
|
110
|
+
self.0
|
|
110
111
|
.modified_data_ids()
|
|
111
112
|
.iter()
|
|
112
|
-
.map(|id| id.
|
|
113
|
-
.collect()
|
|
114
|
-
|
|
115
|
-
serde_wasm_bindgen::to_value(&vec_of_ids).map_err(JsValue::from)
|
|
113
|
+
.map(|id| id.clone().into())
|
|
114
|
+
.collect()
|
|
116
115
|
}
|
|
117
116
|
|
|
118
117
|
#[wasm_bindgen(getter = "allConflictingIndexCollateralVotingFunds")]
|
|
@@ -125,10 +124,18 @@ impl DocumentsBatchWASM {
|
|
|
125
124
|
}
|
|
126
125
|
|
|
127
126
|
#[wasm_bindgen(setter = "transitions")]
|
|
128
|
-
pub fn set_transitions(&mut self, transitions:
|
|
127
|
+
pub fn set_transitions(&mut self, transitions: &js_sys::Array) {
|
|
129
128
|
let rs_transitions = transitions
|
|
129
|
+
.clone()
|
|
130
130
|
.iter()
|
|
131
|
-
.map(|
|
|
131
|
+
.map(|js_document_transition| {
|
|
132
|
+
let document_transition: DocumentTransitionWASM = js_document_transition
|
|
133
|
+
.to_wasm::<DocumentTransitionWASM>("DocumentTransitionWASM")
|
|
134
|
+
.unwrap()
|
|
135
|
+
.clone();
|
|
136
|
+
|
|
137
|
+
DocumentTransition::from(document_transition.clone().clone())
|
|
138
|
+
})
|
|
132
139
|
.collect();
|
|
133
140
|
|
|
134
141
|
self.0.set_transitions(rs_transitions);
|
|
@@ -9,8 +9,8 @@ use dpp::state_transition::documents_batch_transition::document_create_transitio
|
|
|
9
9
|
use dpp::state_transition::documents_batch_transition::document_transition::DocumentTransition;
|
|
10
10
|
use pshenmic_dpp_document::DocumentWASM;
|
|
11
11
|
use pshenmic_dpp_utils::ToSerdeJSONExt;
|
|
12
|
+
use wasm_bindgen::JsValue;
|
|
12
13
|
use wasm_bindgen::prelude::wasm_bindgen;
|
|
13
|
-
use wasm_bindgen::{JsError, JsValue};
|
|
14
14
|
|
|
15
15
|
#[wasm_bindgen(js_name = "DocumentCreateTransitionWASM")]
|
|
16
16
|
#[derive(Clone)]
|
|
@@ -76,7 +76,10 @@ impl DocumentCreateTransitionWASM {
|
|
|
76
76
|
|
|
77
77
|
#[wasm_bindgen(setter = "entropy")]
|
|
78
78
|
pub fn set_entropy(&mut self, js_entropy: Vec<u8>) -> Result<(), JsValue> {
|
|
79
|
-
let entropy
|
|
79
|
+
let mut entropy = [0u8; 32];
|
|
80
|
+
let bytes = js_entropy.as_slice();
|
|
81
|
+
let len = bytes.len().min(32);
|
|
82
|
+
entropy[..len].copy_from_slice(&bytes[..len]);
|
|
80
83
|
|
|
81
84
|
Ok(self.0.set_entropy(entropy))
|
|
82
85
|
}
|
|
@@ -4,7 +4,7 @@ use dpp::state_transition::documents_batch_transition::document_transition::{Doc
|
|
|
4
4
|
use wasm_bindgen::JsValue;
|
|
5
5
|
use wasm_bindgen::prelude::wasm_bindgen;
|
|
6
6
|
use pshenmic_dpp_document::DocumentWASM;
|
|
7
|
-
use
|
|
7
|
+
use pshenmic_dpp_identifier::IdentifierWASM;
|
|
8
8
|
use crate::document_base_transition::DocumentBaseTransitionWASM;
|
|
9
9
|
use crate::document_transition::DocumentTransitionWASM;
|
|
10
10
|
use crate::generators::generate_transfer_transition;
|
|
@@ -31,15 +31,13 @@ impl DocumentTransferTransitionWASM {
|
|
|
31
31
|
document: &DocumentWASM,
|
|
32
32
|
identity_contract_nonce: IdentityNonce,
|
|
33
33
|
document_type_name: String,
|
|
34
|
-
js_recipient_owner_id: JsValue,
|
|
34
|
+
js_recipient_owner_id: &JsValue,
|
|
35
35
|
) -> Result<DocumentTransferTransitionWASM, JsValue> {
|
|
36
|
-
let recipient_owner_id = identifier_from_js_value(&js_recipient_owner_id)?;
|
|
37
|
-
|
|
38
36
|
let rs_transfer_transition = generate_transfer_transition(
|
|
39
37
|
document.clone(),
|
|
40
38
|
identity_contract_nonce,
|
|
41
39
|
document_type_name,
|
|
42
|
-
|
|
40
|
+
IdentifierWASM::try_from(js_recipient_owner_id)?.into(),
|
|
43
41
|
);
|
|
44
42
|
|
|
45
43
|
Ok(DocumentTransferTransitionWASM(rs_transfer_transition))
|
|
@@ -51,8 +49,8 @@ impl DocumentTransferTransitionWASM {
|
|
|
51
49
|
}
|
|
52
50
|
|
|
53
51
|
#[wasm_bindgen(getter = "recipientId")]
|
|
54
|
-
pub fn get_recipient_owner_id(&self) ->
|
|
55
|
-
self.0.recipient_owner_id().
|
|
52
|
+
pub fn get_recipient_owner_id(&self) -> IdentifierWASM {
|
|
53
|
+
self.0.recipient_owner_id().into()
|
|
56
54
|
}
|
|
57
55
|
|
|
58
56
|
#[wasm_bindgen(setter = "base")]
|
|
@@ -63,11 +61,11 @@ impl DocumentTransferTransitionWASM {
|
|
|
63
61
|
#[wasm_bindgen(setter = "recipientId")]
|
|
64
62
|
pub fn set_recipient_owner_id(
|
|
65
63
|
&mut self,
|
|
66
|
-
js_recipient_owner_id: JsValue,
|
|
64
|
+
js_recipient_owner_id: &JsValue,
|
|
67
65
|
) -> Result<(), JsValue> {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
Ok(
|
|
66
|
+
self.0
|
|
67
|
+
.set_recipient_owner_id(IdentifierWASM::try_from(js_recipient_owner_id)?.into());
|
|
68
|
+
Ok(())
|
|
71
69
|
}
|
|
72
70
|
|
|
73
71
|
#[wasm_bindgen(js_name = "toDocumentTransition")]
|
|
@@ -7,7 +7,7 @@ edition = "2024"
|
|
|
7
7
|
crate-type = ["cdylib", "lib"]
|
|
8
8
|
|
|
9
9
|
[dependencies]
|
|
10
|
-
wasm-bindgen = "0.2.100"
|
|
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
|
"state-transitions"
|
|
13
13
|
]}
|
|
@@ -25,8 +25,8 @@ impl TryFrom<JsValue> for BatchTypeWASM {
|
|
|
25
25
|
"delete" => Ok(BatchTypeWASM::Delete),
|
|
26
26
|
"transfer" => Ok(BatchTypeWASM::Transfer),
|
|
27
27
|
"purchase" => Ok(BatchTypeWASM::Purchase),
|
|
28
|
-
"
|
|
29
|
-
"
|
|
28
|
+
"updateprice" => Ok(BatchTypeWASM::UpdatePrice),
|
|
29
|
+
"ignorewhilebumpingrevision" => Ok(BatchTypeWASM::IgnoreWhileBumpingRevision),
|
|
30
30
|
_ => Err(JsValue::from(format!(
|
|
31
31
|
"unknown batch type value: {}",
|
|
32
32
|
enum_val
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
use wasm_bindgen::prelude::wasm_bindgen;
|
|
2
|
+
use wasm_bindgen::{JsError, JsValue};
|
|
3
|
+
|
|
4
|
+
#[wasm_bindgen(js_name = "AssetLockProofTypeWASM")]
|
|
5
|
+
pub enum AssetLockProofTypeWASM {
|
|
6
|
+
Instant = 0,
|
|
7
|
+
Chain = 1,
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
impl From<AssetLockProofTypeWASM> for String {
|
|
11
|
+
fn from(value: AssetLockProofTypeWASM) -> Self {
|
|
12
|
+
match value {
|
|
13
|
+
AssetLockProofTypeWASM::Instant => String::from("Instant"),
|
|
14
|
+
AssetLockProofTypeWASM::Chain => String::from("Chain"),
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
impl TryFrom<JsValue> for AssetLockProofTypeWASM {
|
|
20
|
+
type Error = JsValue;
|
|
21
|
+
|
|
22
|
+
fn try_from(value: JsValue) -> Result<Self, Self::Error> {
|
|
23
|
+
match value.is_string() {
|
|
24
|
+
true => match value.as_string() {
|
|
25
|
+
None => Err(JsValue::from("cannot read value from enum")),
|
|
26
|
+
Some(enum_val) => match enum_val.to_lowercase().as_str() {
|
|
27
|
+
"instant" => Ok(AssetLockProofTypeWASM::Instant),
|
|
28
|
+
"chain" => Ok(AssetLockProofTypeWASM::Chain),
|
|
29
|
+
_ => Err(JsValue::from(format!("unsupported lock type {}", enum_val))),
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
false => match value.as_f64() {
|
|
33
|
+
None => Err(JsValue::from("cannot read value from enum")),
|
|
34
|
+
Some(enum_val) => match enum_val as u8 {
|
|
35
|
+
0 => Ok(AssetLockProofTypeWASM::Instant),
|
|
36
|
+
1 => Ok(AssetLockProofTypeWASM::Chain),
|
|
37
|
+
_ => Err(JsValue::from(format!("unsupported lock type {}", enum_val))),
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
impl TryFrom<u8> for AssetLockProofTypeWASM {
|
|
45
|
+
type Error = JsError;
|
|
46
|
+
fn try_from(value: u8) -> Result<Self, Self::Error> {
|
|
47
|
+
match value {
|
|
48
|
+
0 => Ok(Self::Instant),
|
|
49
|
+
1 => Ok(Self::Chain),
|
|
50
|
+
_ => Err(JsError::new("Unexpected asset lock proof type")),
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
impl TryFrom<u64> for AssetLockProofTypeWASM {
|
|
56
|
+
type Error = JsError;
|
|
57
|
+
|
|
58
|
+
fn try_from(value: u64) -> Result<Self, Self::Error> {
|
|
59
|
+
match value {
|
|
60
|
+
0 => Ok(Self::Instant),
|
|
61
|
+
1 => Ok(Self::Chain),
|
|
62
|
+
_ => Err(JsError::new("Unexpected asset lock proof type")),
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -11,8 +11,10 @@ use wasm_bindgen::JsValue;
|
|
|
11
11
|
use wasm_bindgen::prelude::wasm_bindgen;
|
|
12
12
|
|
|
13
13
|
#[wasm_bindgen(js_name = "PlatformVersionWASM")]
|
|
14
|
+
#[derive(Default)]
|
|
14
15
|
#[allow(non_camel_case_types)]
|
|
15
16
|
pub enum PlatformVersionWASM {
|
|
17
|
+
#[default]
|
|
16
18
|
PLATFORM_V1 = 0,
|
|
17
19
|
PLATFORM_V2 = 1,
|
|
18
20
|
PLATFORM_V3 = 2,
|