pshenmic-dpp 1.0.4 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/build.yml +9 -1
- package/.github/workflows/publish.yml +9 -1
- package/Cargo.lock +222 -76
- package/Cargo.toml +28 -19
- package/README.md +75 -23
- package/babel.config.json +19 -0
- package/dist/wasm/index.d.ts +52 -0
- package/dist/wasm/pshenmic_dpp.d.ts +962 -0
- package/dist/wasm/pshenmic_dpp.js +5565 -966
- 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 +15 -8
- 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 +2 -2
- package/packages/core_script/Cargo.toml +13 -0
- package/packages/core_script/src/lib.rs +69 -0
- package/packages/data_contract/Cargo.toml +4 -3
- package/packages/data_contract/src/lib.rs +209 -33
- package/packages/data_contract_transitions/Cargo.toml +2 -2
- package/packages/data_contract_transitions/src/create/mod.rs +23 -16
- package/packages/data_contract_transitions/src/update/mod.rs +21 -12
- package/packages/document/Cargo.toml +3 -2
- package/packages/document/src/lib.rs +14 -13
- package/packages/document/src/methods/mod.rs +373 -2
- package/packages/{document_batch → documents_batch}/Cargo.toml +7 -4
- package/packages/documents_batch/src/document_base_transition/mod.rs +88 -0
- package/packages/documents_batch/src/document_transition/mod.rs +166 -0
- package/packages/documents_batch/src/generators.rs +122 -0
- package/packages/documents_batch/src/lib.rs +195 -0
- package/packages/documents_batch/src/prefunded_voting_balance/mod.rs +45 -0
- package/packages/documents_batch/src/transitions/create/mod.rs +126 -0
- package/packages/documents_batch/src/transitions/delete/mod.rs +67 -0
- package/packages/documents_batch/src/transitions/mod.rs +6 -0
- package/packages/documents_batch/src/transitions/purchase/mod.rs +91 -0
- package/packages/documents_batch/src/transitions/replace/mod.rs +93 -0
- package/packages/documents_batch/src/transitions/transfer/mod.rs +84 -0
- package/packages/documents_batch/src/transitions/update_price/mod.rs +75 -0
- package/packages/enums/Cargo.toml +4 -4
- package/packages/enums/src/batch/batch_enum.rs +75 -10
- package/packages/enums/src/keys/key_type.rs +46 -0
- package/packages/enums/src/keys/purpose.rs +55 -0
- package/packages/enums/src/keys/security_level.rs +46 -0
- package/packages/enums/src/lib.rs +3 -0
- package/packages/enums/src/lock_types/mod.rs +65 -0
- package/packages/enums/src/network/mod.rs +67 -0
- package/packages/enums/src/platform/mod.rs +68 -8
- 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 +5 -5
- package/packages/identity/src/lib.rs +31 -25
- package/packages/{public_key → identity_public_key}/Cargo.toml +2 -2
- package/packages/{public_key → identity_public_key}/src/lib.rs +74 -27
- package/packages/identity_transitions/Cargo.toml +8 -4
- package/packages/identity_transitions/src/create_transition/mod.rs +102 -37
- 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/public_key_in_creation/mod.rs +197 -0
- 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/mock_bls/Cargo.toml +1 -1
- package/packages/private_key/Cargo.toml +4 -3
- package/packages/private_key/src/lib.rs +44 -6
- package/packages/state_transition/Cargo.toml +6 -4
- package/packages/state_transition/src/lib.rs +102 -36
- package/packages/utils/Cargo.toml +3 -4
- package/packages/utils/src/lib.rs +17 -18
- package/scripts/build-js.sh +22 -5
- package/scripts/build.sh +27 -2
- package/src/lib.rs +8 -1
- 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 +178 -0
- package/tests/DataContractCreateStateTransition.spec.js +109 -0
- package/tests/DataContractUpdateStateTransition.spec.js +109 -0
- package/tests/Document.spec.js +238 -0
- package/tests/DocumentBatchTransition.spec.js +109 -0
- package/tests/DocumentTransition.spec.js +97 -0
- package/tests/DocumentsTransitions.spec.js +705 -0
- package/tests/Identifier.spec.js +84 -0
- package/tests/Identity.spec.js +113 -0
- package/tests/IdentityCreateTransition.spec.js +93 -0
- package/tests/IdentityCreditTransferTransition.spec.js +146 -0
- package/tests/IdentityCreditWithdrawalTransition.spec.js +192 -0
- package/tests/IdentityPublicKey.spec.js +132 -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/PrivateKey.spec.js +73 -0
- package/tests/PublicKeyInCreation.spec.js +258 -0
- package/tests/TxOut.spec.js +76 -0
- package/tests/mocks/DataContract/DataContract.json +153 -0
- package/tests/mocks/DataContract/index.js +6 -0
- package/tests/mocks/Document/DataContract.json +23 -0
- package/tests/mocks/Document/document.json +3 -0
- package/tests/mocks/Document/document2.json +3 -0
- package/tests/mocks/Document/index.js +11 -0
- package/tests/mocks/Identity/index.js +7 -0
- package/tests/mocks/Locks/index.js +5 -0
- package/tests/mocks/PrivateKey/index.js +5 -0
- package/tests/mocks/PublicKey/index.js +14 -0
- package/tests/utils/hex.js +15 -0
- package/tests/utils/wasm.js +14 -0
- package/typings/index.d.ts +52 -0
- package/packages/document/src/methods/js.rs +0 -260
- package/packages/document/src/methods/rust.rs +0 -92
- package/packages/document_batch/src/generators.rs +0 -63
- package/packages/document_batch/src/lib.rs +0 -228
- package/packages/identity_transitions/src/create_transition/public_key_in_creation/mod.rs +0 -146
|
@@ -1,11 +1,18 @@
|
|
|
1
|
-
use dpp::
|
|
2
|
-
use dpp::
|
|
1
|
+
use dpp::dashcore::secp256k1::hashes::hex::Case::Lower;
|
|
2
|
+
use dpp::dashcore::secp256k1::hashes::hex::DisplayHex;
|
|
3
|
+
use dpp::identity::{KeyID, KeyType};
|
|
4
|
+
use dpp::platform_value::BinaryData;
|
|
5
|
+
use dpp::prelude::UserFeeIncrease;
|
|
6
|
+
use dpp::serialization::{PlatformDeserializable, PlatformSerializable, Signable};
|
|
3
7
|
use dpp::state_transition::StateTransition;
|
|
4
8
|
use pshenmic_dpp_enums::keys::key_type::KeyTypeWASM;
|
|
9
|
+
use pshenmic_dpp_enums::keys::purpose::PurposeWASM;
|
|
10
|
+
use pshenmic_dpp_identifier::IdentifierWASM;
|
|
5
11
|
use pshenmic_dpp_mock_bls::MockBLS;
|
|
6
12
|
use pshenmic_dpp_private_key::PrivateKeyWASM;
|
|
7
13
|
use pshenmic_dpp_public_key::IdentityPublicKeyWASM;
|
|
8
14
|
use pshenmic_dpp_utils::WithJsError;
|
|
15
|
+
use sha2::{Digest, Sha256};
|
|
9
16
|
use wasm_bindgen::JsValue;
|
|
10
17
|
use wasm_bindgen::prelude::wasm_bindgen;
|
|
11
18
|
|
|
@@ -27,65 +34,55 @@ impl From<StateTransitionWASM> for StateTransition {
|
|
|
27
34
|
|
|
28
35
|
#[wasm_bindgen]
|
|
29
36
|
impl StateTransitionWASM {
|
|
30
|
-
#[wasm_bindgen(js_name=sign)]
|
|
37
|
+
#[wasm_bindgen(js_name = "sign")]
|
|
31
38
|
pub fn sign(
|
|
32
39
|
&mut self,
|
|
33
40
|
private_key: &PrivateKeyWASM,
|
|
34
41
|
public_key: &IdentityPublicKeyWASM,
|
|
35
|
-
) -> Result<
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
Err(e) => wasm_bindgen::throw_str(&e.to_string()),
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
match bytes {
|
|
53
|
-
Ok(bytes) => Ok(JsValue::from(bytes.clone())),
|
|
54
|
-
Err(e) => Ok(JsValue::from_str(&format!("{}", e))),
|
|
55
|
-
}
|
|
42
|
+
) -> Result<Vec<u8>, JsValue> {
|
|
43
|
+
self.0
|
|
44
|
+
.sign(
|
|
45
|
+
&public_key.clone().into(),
|
|
46
|
+
private_key.get_bytes().as_slice(),
|
|
47
|
+
&MockBLS {},
|
|
48
|
+
)
|
|
49
|
+
.with_js_error()?;
|
|
50
|
+
|
|
51
|
+
self.0.set_signature(self.0.signature().clone());
|
|
52
|
+
self.0
|
|
53
|
+
.set_signature_public_key_id(self.0.signature_public_key_id().unwrap());
|
|
54
|
+
|
|
55
|
+
self.0.serialize_to_bytes().with_js_error()
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
#[wasm_bindgen(js_name=signByPrivateKey)]
|
|
58
|
+
#[wasm_bindgen(js_name = "signByPrivateKey")]
|
|
59
59
|
pub fn sign_by_private_key(
|
|
60
60
|
&mut self,
|
|
61
61
|
private_key: &PrivateKeyWASM,
|
|
62
|
-
|
|
63
|
-
) -> JsValue {
|
|
62
|
+
js_key_type: JsValue,
|
|
63
|
+
) -> Result<Vec<u8>, JsValue> {
|
|
64
|
+
let key_type = KeyTypeWASM::try_from(js_key_type)?;
|
|
65
|
+
|
|
64
66
|
let _sig = self
|
|
65
67
|
.0
|
|
66
68
|
.sign_by_private_key(
|
|
67
|
-
&private_key.
|
|
69
|
+
&private_key.get_bytes().as_slice(),
|
|
68
70
|
KeyType::from(key_type),
|
|
69
71
|
&MockBLS {},
|
|
70
72
|
)
|
|
71
73
|
.with_js_error();
|
|
72
74
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
match bytes {
|
|
76
|
-
Ok(bytes) => JsValue::from(bytes.clone()),
|
|
77
|
-
Err(err) => err,
|
|
78
|
-
}
|
|
75
|
+
self.0.serialize_to_bytes().with_js_error()
|
|
79
76
|
}
|
|
80
77
|
|
|
81
|
-
#[wasm_bindgen(js_name=toBytes)]
|
|
78
|
+
#[wasm_bindgen(js_name = "toBytes")]
|
|
82
79
|
pub fn to_bytes(&self) -> Result<JsValue, JsValue> {
|
|
83
80
|
let bytes = self.0.serialize_to_bytes().with_js_error()?;
|
|
84
81
|
|
|
85
82
|
Ok(JsValue::from(bytes.clone()))
|
|
86
83
|
}
|
|
87
84
|
|
|
88
|
-
#[wasm_bindgen(js_name=fromBytes)]
|
|
85
|
+
#[wasm_bindgen(js_name = "fromBytes")]
|
|
89
86
|
pub fn from_bytes(bytes: Vec<u8>) -> Result<StateTransitionWASM, JsValue> {
|
|
90
87
|
let st = StateTransition::deserialize_from_bytes(bytes.as_slice());
|
|
91
88
|
|
|
@@ -94,4 +91,73 @@ impl StateTransitionWASM {
|
|
|
94
91
|
Ok(transition) => Ok(StateTransitionWASM(transition)),
|
|
95
92
|
}
|
|
96
93
|
}
|
|
94
|
+
|
|
95
|
+
#[wasm_bindgen(js_name = "hash")]
|
|
96
|
+
pub fn get_hash(&self, skip_signature: bool) -> Result<String, JsValue> {
|
|
97
|
+
let payload: Vec<u8>;
|
|
98
|
+
|
|
99
|
+
if skip_signature {
|
|
100
|
+
payload = self.0.signable_bytes().with_js_error()?;
|
|
101
|
+
} else {
|
|
102
|
+
payload = dpp::serialization::PlatformSerializable::serialize_to_bytes(&self.0)
|
|
103
|
+
.with_js_error()?;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
Ok(Sha256::digest(payload).to_hex_string(Lower))
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
#[wasm_bindgen(js_name = "getActionType")]
|
|
110
|
+
pub fn get_action_type(&self) -> String {
|
|
111
|
+
self.0.name()
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
#[wasm_bindgen(js_name = "getOwnerId")]
|
|
115
|
+
pub fn get_owner_id(&self) -> IdentifierWASM {
|
|
116
|
+
self.0.owner_id().into()
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
#[wasm_bindgen(getter = "signature")]
|
|
120
|
+
pub fn get_signature(&self) -> Vec<u8> {
|
|
121
|
+
self.0.signature().to_vec()
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
#[wasm_bindgen(getter = "signaturePublicKeyId")]
|
|
125
|
+
pub fn get_signature_public_key_id(&self) -> Option<KeyID> {
|
|
126
|
+
self.0.signature_public_key_id()
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
#[wasm_bindgen(getter = "userFeeIncrease")]
|
|
130
|
+
pub fn get_user_fee_increase(&self) -> UserFeeIncrease {
|
|
131
|
+
self.0.user_fee_increase()
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
#[wasm_bindgen(js_name = "getPurposeRequirement")]
|
|
135
|
+
pub fn get_purpose_requirement(&self) -> Option<Vec<String>> {
|
|
136
|
+
let requirements = self.0.purpose_requirement();
|
|
137
|
+
|
|
138
|
+
match requirements {
|
|
139
|
+
None => None,
|
|
140
|
+
Some(req) => Some(
|
|
141
|
+
req.iter()
|
|
142
|
+
.map(|purpose| PurposeWASM::from(purpose.clone()))
|
|
143
|
+
.map(String::from)
|
|
144
|
+
.collect(),
|
|
145
|
+
),
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
#[wasm_bindgen(setter = "signature")]
|
|
150
|
+
pub fn set_signature(&mut self, signature: Vec<u8>) {
|
|
151
|
+
self.0.set_signature(BinaryData::from(signature))
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
#[wasm_bindgen(setter = "signaturePublicKeyId")]
|
|
155
|
+
pub fn set_signature_public_key_id(&mut self, key_id: KeyID) {
|
|
156
|
+
self.0.set_signature_public_key_id(key_id)
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
#[wasm_bindgen(setter = "userFeeIncrease")]
|
|
160
|
+
pub fn set_user_fee_increase(&mut self, user_fee_increase: UserFeeIncrease) {
|
|
161
|
+
self.0.set_user_fee_increase(user_fee_increase)
|
|
162
|
+
}
|
|
97
163
|
}
|
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
[package]
|
|
2
2
|
name = "pshenmic_dpp_utils"
|
|
3
|
-
version =
|
|
3
|
+
version.workspace = true
|
|
4
4
|
edition = "2024"
|
|
5
5
|
|
|
6
6
|
[lib]
|
|
7
7
|
crate-type = ["cdylib", "lib"]
|
|
8
8
|
|
|
9
9
|
[dependencies]
|
|
10
|
-
wasm-bindgen = { version = "=0.2.100", features = ["serde-serialize"] }
|
|
10
|
+
wasm-bindgen = { version = "=0.2.100", default-features = false, features = ["serde-serialize"] }
|
|
11
11
|
anyhow = { version = "1.0.75" }
|
|
12
12
|
dpp = { git = "https://github.com/dashpay/platform", branch = "master", features = [
|
|
13
13
|
"platform-value",
|
|
14
14
|
"document-json-conversion"
|
|
15
|
-
]}
|
|
15
|
+
] }
|
|
16
16
|
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" }
|
|
@@ -4,10 +4,9 @@ use anyhow::{Context, anyhow, bail};
|
|
|
4
4
|
use dpp::ProtocolError;
|
|
5
5
|
use dpp::identifier::Identifier;
|
|
6
6
|
use dpp::platform_value::Value;
|
|
7
|
-
use dpp::platform_value::string_encoding::Encoding;
|
|
7
|
+
use dpp::platform_value::string_encoding::Encoding::Base58;
|
|
8
8
|
use dpp::util::hash::hash_double_to_vec;
|
|
9
|
-
use
|
|
10
|
-
use js_sys::Function;
|
|
9
|
+
use js_sys::{Function, Uint8Array};
|
|
11
10
|
use serde::de::DeserializeOwned;
|
|
12
11
|
use serde_json::Value as JsonValue;
|
|
13
12
|
use std::collections::BTreeMap;
|
|
@@ -222,9 +221,6 @@ pub fn get_bool_from_options(
|
|
|
222
221
|
}
|
|
223
222
|
}
|
|
224
223
|
|
|
225
|
-
#[allow(dead_code)]
|
|
226
|
-
#[deprecated(note = "This function is marked as unused.")]
|
|
227
|
-
#[allow(deprecated)]
|
|
228
224
|
pub fn get_class_name(value: &JsValue) -> String {
|
|
229
225
|
js_sys::Object::get_prototype_of(value)
|
|
230
226
|
.constructor()
|
|
@@ -274,7 +270,7 @@ pub fn generate_document_id_v0(
|
|
|
274
270
|
owner_id: &Identifier,
|
|
275
271
|
document_type_name: &str,
|
|
276
272
|
entropy: &[u8],
|
|
277
|
-
) -> Identifier {
|
|
273
|
+
) -> Result<Identifier, JsValue> {
|
|
278
274
|
let mut buf: Vec<u8> = vec![];
|
|
279
275
|
|
|
280
276
|
buf.extend_from_slice(&contract_id.to_buffer());
|
|
@@ -282,7 +278,7 @@ pub fn generate_document_id_v0(
|
|
|
282
278
|
buf.extend_from_slice(document_type_name.as_bytes());
|
|
283
279
|
buf.extend_from_slice(entropy);
|
|
284
280
|
|
|
285
|
-
Identifier::from_bytes(&hash_double_to_vec(&buf)).
|
|
281
|
+
Identifier::from_bytes(&hash_double_to_vec(&buf)).map_err(|e| JsValue::from(e.to_string()))
|
|
286
282
|
}
|
|
287
283
|
|
|
288
284
|
#[wasm_bindgen(raw_module = "../identifier_utils/Identifier.js")]
|
|
@@ -325,18 +321,21 @@ pub fn identifier_from_js_value(js_value: &JsValue) -> Result<Identifier, JsValu
|
|
|
325
321
|
));
|
|
326
322
|
}
|
|
327
323
|
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
serde_json::Value::Array(arr) => {
|
|
331
|
-
let bytes: Vec<u8> = arr.into_iter().map(value_to_u8).try_collect()?;
|
|
332
|
-
Identifier::from_bytes(&bytes)
|
|
333
|
-
.map_err(ProtocolError::ValueError)
|
|
334
|
-
.with_js_error()
|
|
335
|
-
}
|
|
336
|
-
serde_json::Value::String(string) => Identifier::from_string(&string, Encoding::Base58)
|
|
324
|
+
match js_value.is_string() {
|
|
325
|
+
true => Identifier::from_string(js_value.as_string().unwrap_or("".into()).as_str(), Base58)
|
|
337
326
|
.map_err(ProtocolError::ValueError)
|
|
338
327
|
.with_js_error(),
|
|
339
|
-
|
|
328
|
+
false => match js_value.is_object() || js_value.is_array() {
|
|
329
|
+
true => {
|
|
330
|
+
let uint8_array = Uint8Array::from(js_value.clone());
|
|
331
|
+
let bytes = uint8_array.to_vec();
|
|
332
|
+
|
|
333
|
+
Identifier::from_bytes(&bytes)
|
|
334
|
+
.map_err(ProtocolError::ValueError)
|
|
335
|
+
.with_js_error()
|
|
336
|
+
}
|
|
337
|
+
false => Err(JsValue::from_str("Invalid ID. Expected array or string")),
|
|
338
|
+
},
|
|
340
339
|
}
|
|
341
340
|
}
|
|
342
341
|
|
package/scripts/build-js.sh
CHANGED
|
@@ -6,11 +6,18 @@ DIST_WASM_DIR="$DIST_DIR/wasm"
|
|
|
6
6
|
DIST_WASM_BINARY_BASE_64="$DIST_WASM_DIR/pshenmic_dpp_bg.js"
|
|
7
7
|
DIST_WASM_BINARY_RAW="$DIST_WASM_DIR/pshenmic_dpp_bg.wasm"
|
|
8
8
|
DIST_WASM_JS="$DIST_WASM_DIR/pshenmic_dpp.js"
|
|
9
|
+
DIST_WASM_TS_BG="$DIST_WASM_DIR/pshenmic_dpp_bg.wasm.d.ts"
|
|
10
|
+
DIST_WASM_TS="$DIST_WASM_DIR/pshenmic_dpp.d.ts"
|
|
11
|
+
DIST_WASM_TS_INDEX="$DIST_WASM_DIR/index.d.ts"
|
|
12
|
+
|
|
9
13
|
|
|
10
14
|
## Paths to wasm files produced by wasm-bindgen
|
|
11
15
|
WASM_DIR="$PWD/wasm"
|
|
12
16
|
WASM_JS_CODE_PATH="$WASM_DIR/pshenmic_dpp.js"
|
|
13
17
|
WASM_BINARY_PATH="$WASM_DIR/pshenmic_dpp_bg.wasm"
|
|
18
|
+
WASM_TS_BG_CODE_PATH="$WASM_DIR/pshenmic_dpp_bg.wasm.d.ts"
|
|
19
|
+
WASM_TS_CODE_PATH="$WASM_DIR/pshenmic_dpp.d.ts"
|
|
20
|
+
WASM_TS_INDEX_CODE_PATH="$PWD/typings/index.d.ts"
|
|
14
21
|
|
|
15
22
|
# Create directory in dist to save transpiled wasm code and TS typings
|
|
16
23
|
mkdir -p $DIST_WASM_DIR
|
|
@@ -20,6 +27,10 @@ rm -rf $DIST_WASM_BINARY_BASE_64
|
|
|
20
27
|
rm -rf $DIST_WASM_BINARY_RAW
|
|
21
28
|
rm -rf $DIST_WASM_JS
|
|
22
29
|
|
|
30
|
+
rm -rf $DIST_WASM_TS_INDEX
|
|
31
|
+
rm -rf $DIST_WASM_TS_BG
|
|
32
|
+
rm -rf $DIST_WASM_TS
|
|
33
|
+
|
|
23
34
|
## Converting wasm into base64 and saving it to dist folder
|
|
24
35
|
|
|
25
36
|
if [[ "${RAW}" == "true" ]]; then
|
|
@@ -27,13 +38,19 @@ if [[ "${RAW}" == "true" ]]; then
|
|
|
27
38
|
else
|
|
28
39
|
echo "Converting wasm binary into base64 module"
|
|
29
40
|
WASM_BUILD_BASE_64=$(base64 -i "$WASM_BINARY_PATH")
|
|
30
|
-
echo '
|
|
41
|
+
echo 'export default "'${WASM_BUILD_BASE_64}'"' > "$DIST_WASM_BINARY_BASE_64"
|
|
31
42
|
fi
|
|
32
43
|
|
|
33
|
-
|
|
34
|
-
## and save directly to dist folder to avoid re-generating TS declarations
|
|
35
|
-
echo "Transpiling wasm ES Modules to CommonJS"
|
|
44
|
+
echo "Copying ES module to dist"
|
|
36
45
|
cp $WASM_JS_CODE_PATH $DIST_WASM_JS
|
|
37
46
|
|
|
47
|
+
echo "Copying TS types to dist"
|
|
48
|
+
cp $WASM_TS_INDEX_CODE_PATH $DIST_WASM_TS_INDEX
|
|
49
|
+
cp $WASM_TS_BG_CODE_PATH $DIST_WASM_TS_BG
|
|
50
|
+
cp $WASM_TS_CODE_PATH $DIST_WASM_TS
|
|
51
|
+
|
|
38
52
|
echo "Cleaning wasm build"
|
|
39
|
-
|
|
53
|
+
rm -rf $WASM_DIR
|
|
54
|
+
|
|
55
|
+
echo "Total build size: "
|
|
56
|
+
du -sh $DIST_WASM_DIR
|
package/scripts/build.sh
CHANGED
|
@@ -9,8 +9,11 @@ PROFILE=release
|
|
|
9
9
|
|
|
10
10
|
OUTPUT_FILE="${PWD}/wasm/pshenmic_dpp_bg.wasm"
|
|
11
11
|
|
|
12
|
+
RUSTFLAGS="-C target-feature=+crt-static -C embed-bitcode=no -C metadata=reduced -C link-dead-code=no -C panic=abort"
|
|
13
|
+
|
|
12
14
|
BUILD_COMMAND="cargo build --config net.git-fetch-with-cli=true --target=${TARGET} ${PROFILE_ARG}"
|
|
13
|
-
|
|
15
|
+
STRIP_COMMAND=" wasm-snip ${PWD}/target/${TARGET}/${PROFILE}/pshenmic_dpp.wasm -o ${PWD}/target/${TARGET}/${PROFILE}/pshenmic_dpp.wasm --snip-rust-fmt-code --snip-rust-panicking-code"
|
|
16
|
+
BINDGEN_COMMAND="wasm-bindgen --typescript --out-dir=${OUTPUT_DIR} --target=web --omit-default-module-path ${PWD}/target/${TARGET}/${PROFILE}/pshenmic_dpp.wasm"
|
|
14
17
|
|
|
15
18
|
if ! [[ -d ${OUTPUT_DIR} ]]; then
|
|
16
19
|
mkdir -p "${OUTPUT_DIR}"
|
|
@@ -23,12 +26,34 @@ if [[ "${OSTYPE}" == "darwin"* ]]; then
|
|
|
23
26
|
AR=${AR_PATH} CC=${CLANG_PATH} ${BINDGEN_COMMAND}
|
|
24
27
|
else
|
|
25
28
|
${BUILD_COMMAND}
|
|
29
|
+
${STRIP_COMMAND}
|
|
26
30
|
${BINDGEN_COMMAND}
|
|
27
31
|
fi
|
|
28
32
|
|
|
29
33
|
if command -v wasm-opt &> /dev/null; then
|
|
30
34
|
echo "Optimizing wasm using Binaryen"
|
|
31
|
-
wasm-opt
|
|
35
|
+
wasm-opt \
|
|
36
|
+
--generate-global-effects \
|
|
37
|
+
--enable-bulk-memory \
|
|
38
|
+
--enable-nontrapping-float-to-int \
|
|
39
|
+
-Oz \
|
|
40
|
+
-tnh \
|
|
41
|
+
--flatten \
|
|
42
|
+
--rereloop \
|
|
43
|
+
-Oz \
|
|
44
|
+
--converge \
|
|
45
|
+
--vacuum \
|
|
46
|
+
--dce \
|
|
47
|
+
--inlining-optimizing \
|
|
48
|
+
--merge-blocks \
|
|
49
|
+
--simplify-locals \
|
|
50
|
+
--optimize-instructions \
|
|
51
|
+
-Oz \
|
|
52
|
+
--gufa \
|
|
53
|
+
-Oz \
|
|
54
|
+
"$OUTPUT_FILE" \
|
|
55
|
+
-o \
|
|
56
|
+
"${OUTPUT_FILE}"
|
|
32
57
|
else
|
|
33
58
|
echo "wasm-opt command not found. Skipping wasm optimization."
|
|
34
59
|
fi
|
package/src/lib.rs
CHANGED
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
#![no_std]
|
|
2
2
|
#![no_main]
|
|
3
3
|
|
|
4
|
+
extern crate wee_alloc;
|
|
5
|
+
|
|
6
|
+
// allows to save 7 kb
|
|
7
|
+
#[global_allocator]
|
|
8
|
+
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
|
|
9
|
+
|
|
4
10
|
pub use pshenmic_dpp_data_contract;
|
|
5
11
|
pub use pshenmic_dpp_data_contract_transitions;
|
|
6
|
-
pub use pshenmic_dpp_document_batch;
|
|
7
12
|
pub use pshenmic_dpp_document_search;
|
|
13
|
+
pub use pshenmic_dpp_documents_batch;
|
|
8
14
|
pub use pshenmic_dpp_enums;
|
|
15
|
+
pub use pshenmic_dpp_identifier;
|
|
9
16
|
pub use pshenmic_dpp_identity;
|
|
10
17
|
pub use pshenmic_dpp_identity_transitions;
|
|
11
18
|
pub use pshenmic_dpp_state_transition;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
const assert = require('assert')
|
|
2
|
+
const { describe, it, before } = require('mocha')
|
|
3
|
+
const initWasm = require('./utils/wasm')
|
|
4
|
+
const { instantLockBytes, transactionBytes } = require('./mocks/Locks')
|
|
5
|
+
|
|
6
|
+
let wasm
|
|
7
|
+
|
|
8
|
+
describe('AssetLockProof', function () {
|
|
9
|
+
before(async function () {
|
|
10
|
+
wasm = initWasm()
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
describe('serialization / deserialization', function () {
|
|
14
|
+
it('should allow to get instant lock proof via constructor', () => {
|
|
15
|
+
const instantLockProof = new wasm.AssetLockProofWASM('instant')
|
|
16
|
+
|
|
17
|
+
assert.equal(instantLockProof.constructor.name, 'AssetLockProofWASM')
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
it('shouldn\'t allow to get chain lock proof via constructor', () => {
|
|
21
|
+
try {
|
|
22
|
+
new wasm.AssetLockProofWASM('chain')
|
|
23
|
+
} catch (e) {
|
|
24
|
+
assert.ok(true)
|
|
25
|
+
return
|
|
26
|
+
}
|
|
27
|
+
assert.ok()
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
it('should allow to create instant lock proof from values', () => {
|
|
31
|
+
const instantLockProof = wasm.AssetLockProofWASM.createInstantAssetLockProof(instantLockBytes, transactionBytes, 0)
|
|
32
|
+
|
|
33
|
+
assert.equal(instantLockProof.constructor.name, 'AssetLockProofWASM')
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
it('should allow to create chain lock proof from values', () => {
|
|
37
|
+
const outpoint = new wasm.OutPointWASM('e8b43025641eea4fd21190f01bd870ef90f1a8b199d8fc3376c5b62c0b1a179d', 1)
|
|
38
|
+
|
|
39
|
+
const chainLockProof = wasm.AssetLockProofWASM.createChainAssetLockProof(1, outpoint)
|
|
40
|
+
|
|
41
|
+
assert.equal(chainLockProof.constructor.name, 'AssetLockProofWASM')
|
|
42
|
+
})
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
describe('getters', function () {
|
|
46
|
+
it('should allow to get lock type', () => {
|
|
47
|
+
const outpoint = new wasm.OutPointWASM('e8b43025641eea4fd21190f01bd870ef90f1a8b199d8fc3376c5b62c0b1a179d', 1)
|
|
48
|
+
|
|
49
|
+
const chainLockProof = wasm.AssetLockProofWASM.createChainAssetLockProof(1, outpoint)
|
|
50
|
+
|
|
51
|
+
const instantLockProof = new wasm.AssetLockProofWASM('instant')
|
|
52
|
+
|
|
53
|
+
assert.equal(chainLockProof.getLockType(), 'Chain')
|
|
54
|
+
assert.equal(instantLockProof.getLockType(), 'Instant')
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
it('should allow to get lock instances', () => {
|
|
58
|
+
const outpoint = new wasm.OutPointWASM('e8b43025641eea4fd21190f01bd870ef90f1a8b199d8fc3376c5b62c0b1a179d', 1)
|
|
59
|
+
|
|
60
|
+
const chainLockProof = wasm.AssetLockProofWASM.createChainAssetLockProof(1, outpoint)
|
|
61
|
+
|
|
62
|
+
const instantLockProof = new wasm.AssetLockProofWASM('instant')
|
|
63
|
+
|
|
64
|
+
assert.equal(chainLockProof.getChainLockProof().constructor.name, 'ChainAssetLockProofWASM')
|
|
65
|
+
assert.equal(instantLockProof.getInstantLockProof().constructor.name, 'InstantAssetLockProofWASM')
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
it('should allow to return object of lock', () => {
|
|
69
|
+
const instantLockProof = new wasm.AssetLockProofWASM('instant')
|
|
70
|
+
|
|
71
|
+
const expected = {
|
|
72
|
+
instantLock: [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
|
73
|
+
transaction: [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 0, 255, 255, 255, 255, 1, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0],
|
|
74
|
+
outputIndex: 0
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
assert.deepEqual(instantLockProof.toObject(), expected)
|
|
78
|
+
})
|
|
79
|
+
})
|
|
80
|
+
})
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
const assert = require('assert')
|
|
2
|
+
const { describe, it, before } = require('mocha')
|
|
3
|
+
const initWasm = require('./utils/wasm')
|
|
4
|
+
|
|
5
|
+
let wasm
|
|
6
|
+
|
|
7
|
+
describe('InstantLock', function () {
|
|
8
|
+
before(async function () {
|
|
9
|
+
wasm = initWasm()
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
describe('serialization / deserialization', function () {
|
|
13
|
+
it('should allow to create chain lock proof from values', () => {
|
|
14
|
+
const outpoint = new wasm.OutPointWASM('e8b43025641eea4fd21190f01bd870ef90f1a8b199d8fc3376c5b62c0b1a179d', 1)
|
|
15
|
+
const chainlock = new wasm.ChainAssetLockProofWASM(11, outpoint)
|
|
16
|
+
|
|
17
|
+
assert.notEqual(chainlock.__wbg_ptr, 0)
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
it('should allow to create chain lock proof from object', () => {
|
|
21
|
+
const outpoint = new wasm.OutPointWASM('e8b43025641eea4fd21190f01bd870ef90f1a8b199d8fc3376c5b62c0b1a179d', 1)
|
|
22
|
+
const chainlock = wasm.ChainAssetLockProofWASM.fromRawObject({
|
|
23
|
+
coreChainLockedHeight: 11,
|
|
24
|
+
outPoint: Array.from(outpoint.toBytes())
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
assert.notEqual(chainlock.__wbg_ptr, 0)
|
|
28
|
+
})
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
describe('getters', function () {
|
|
32
|
+
it('should allow to get coreChainLockedHeight', () => {
|
|
33
|
+
const outpoint = new wasm.OutPointWASM('e8b43025641eea4fd21190f01bd870ef90f1a8b199d8fc3376c5b62c0b1a179d', 1)
|
|
34
|
+
const chainlock = new wasm.ChainAssetLockProofWASM(11, outpoint)
|
|
35
|
+
|
|
36
|
+
assert.equal(chainlock.coreChainLockedHeight, 11)
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
it('should allow to get outPoint', () => {
|
|
40
|
+
const outpoint = new wasm.OutPointWASM('e8b43025641eea4fd21190f01bd870ef90f1a8b199d8fc3376c5b62c0b1a179d', 1)
|
|
41
|
+
const chainlock = new wasm.ChainAssetLockProofWASM(11, outpoint)
|
|
42
|
+
|
|
43
|
+
assert.equal(chainlock.outPoint.constructor.name, 'OutPointWASM')
|
|
44
|
+
})
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
describe('setters', function () {
|
|
48
|
+
it('should allow to set coreChainLockedHeight', () => {
|
|
49
|
+
const outpoint = new wasm.OutPointWASM('e8b43025641eea4fd21190f01bd870ef90f1a8b199d8fc3376c5b62c0b1a179d', 1)
|
|
50
|
+
const chainlock = new wasm.ChainAssetLockProofWASM(11, outpoint)
|
|
51
|
+
|
|
52
|
+
chainlock.coreChainLockedHeight = 33
|
|
53
|
+
|
|
54
|
+
assert.equal(chainlock.coreChainLockedHeight, 33)
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
it('should allow to get outPoint', () => {
|
|
58
|
+
const outpoint = new wasm.OutPointWASM('e8b43025641eea4fd21190f01bd870ef90f1a8b199d8fc3376c5b62c0b1a179d', 1)
|
|
59
|
+
const chainlock = new wasm.ChainAssetLockProofWASM(11, outpoint)
|
|
60
|
+
|
|
61
|
+
const newOutpoint = new wasm.OutPointWASM('e8b43025641eea4fd21190f01bd870ef90f1a8b199d8fc3376c5b62c0b1a179d', 222)
|
|
62
|
+
|
|
63
|
+
chainlock.outPoint = newOutpoint
|
|
64
|
+
|
|
65
|
+
assert.equal(chainlock.outPoint.getVOUT(), 222)
|
|
66
|
+
assert.notEqual(newOutpoint.__wbg_ptr, 0)
|
|
67
|
+
})
|
|
68
|
+
})
|
|
69
|
+
})
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
const assert = require('assert')
|
|
2
|
+
const { describe, it, before } = require('mocha')
|
|
3
|
+
const initWasm = require('./utils/wasm')
|
|
4
|
+
|
|
5
|
+
let wasm
|
|
6
|
+
|
|
7
|
+
describe('CoreScript', function () {
|
|
8
|
+
before(async function () {
|
|
9
|
+
wasm = initWasm()
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
describe('serialization / deserialization', function () {
|
|
13
|
+
it('should allow to create from bytes', () => {
|
|
14
|
+
const script = wasm.CoreScriptWASM.fromBytes(Buffer.from('76a914c3dbfd40e7f8a4845c2f8e868a167c984049764988ac', 'hex'))
|
|
15
|
+
|
|
16
|
+
assert.notEqual(script._wbg_ptr, 0)
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
it('should allow to create P2PKH', () => {
|
|
20
|
+
const script = wasm.CoreScriptWASM.newP2PKH([195, 219, 253, 64, 231, 248, 164, 132, 92, 47, 142, 134, 138, 22, 124, 152, 64, 73, 118, 73])
|
|
21
|
+
|
|
22
|
+
assert.notEqual(script._wbg_ptr, 0)
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
it('should allow to create P2SH', () => {
|
|
26
|
+
const script = wasm.CoreScriptWASM.newP2SH([195, 219, 253, 64, 231, 248, 164, 132, 92, 47, 142, 134, 138, 22, 124, 152, 64, 73, 118, 73])
|
|
27
|
+
|
|
28
|
+
assert.notEqual(script._wbg_ptr, 0)
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
it('should allow to convert to asm P2PKH', () => {
|
|
32
|
+
const script = wasm.CoreScriptWASM.newP2PKH([195, 219, 253, 64, 231, 248, 164, 132, 92, 47, 142, 134, 138, 22, 124, 152, 64, 73, 118, 73])
|
|
33
|
+
|
|
34
|
+
assert.equal(script.toASMString(), 'OP_DUP OP_HASH160 OP_PUSHBYTES_20 c3dbfd40e7f8a4845c2f8e868a167c9840497649 OP_EQUALVERIFY OP_CHECKSIG')
|
|
35
|
+
})
|
|
36
|
+
})
|
|
37
|
+
})
|