pshenmic-dpp 1.0.3 → 1.0.5
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 +8 -0
- package/.github/workflows/publish.yml +8 -0
- package/Cargo.lock +89 -28
- package/Cargo.toml +22 -18
- package/README.md +66 -23
- package/babel.config.json +19 -0
- package/dist/wasm/pshenmic_dpp.js +2992 -402
- package/dist/wasm/pshenmic_dpp_bg.js +1 -1
- package/package.json +13 -6
- package/packages/{cbor-conversation → cbor_conversation}/Cargo.toml +1 -5
- package/packages/data_contract/Cargo.toml +3 -7
- package/packages/data_contract/src/lib.rs +234 -47
- package/packages/{document_batch → data_contract_transitions}/Cargo.toml +6 -14
- package/packages/data_contract_transitions/src/create/mod.rs +161 -0
- package/packages/data_contract_transitions/src/lib.rs +2 -0
- package/packages/data_contract_transitions/src/update/mod.rs +144 -0
- package/packages/document/Cargo.toml +2 -7
- package/packages/document/src/lib.rs +1 -1
- package/packages/document/src/methods/mod.rs +370 -2
- package/packages/documents_batch/Cargo.toml +19 -0
- package/packages/documents_batch/src/document_base_transition/mod.rs +92 -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 +188 -0
- package/packages/documents_batch/src/prefunded_voting_balance/mod.rs +45 -0
- package/packages/documents_batch/src/transitions/create/mod.rs +123 -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 +86 -0
- package/packages/documents_batch/src/transitions/update_price/mod.rs +75 -0
- package/packages/enums/Cargo.toml +2 -5
- 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 +1 -0
- package/packages/enums/src/network/mod.rs +67 -0
- package/packages/enums/src/platform/mod.rs +66 -8
- package/packages/identity/Cargo.toml +2 -7
- package/packages/identity/src/lib.rs +25 -14
- package/packages/{public_key → identity_public_key}/Cargo.toml +2 -6
- package/packages/{public_key → identity_public_key}/src/lib.rs +74 -27
- package/packages/identity_transitions/Cargo.toml +3 -7
- package/packages/identity_transitions/src/create_transition/mod.rs +5 -3
- package/packages/identity_transitions/src/create_transition/public_key_in_creation/mod.rs +25 -21
- package/packages/mock_bls/Cargo.toml +2 -6
- package/packages/private_key/Cargo.toml +2 -5
- package/packages/private_key/src/lib.rs +44 -6
- package/packages/state_transition/Cargo.toml +4 -7
- package/packages/state_transition/src/lib.rs +106 -40
- package/packages/utils/Cargo.toml +1 -6
- package/packages/utils/src/lib.rs +17 -15
- package/scripts/build-js.sh +8 -6
- package/scripts/build.sh +22 -1
- package/src/lib.rs +8 -1
- package/tests/DataContract.spec.js +175 -0
- package/tests/DataContractCreateStateTransition.spec.js +109 -0
- package/tests/DataContractUpdateStateTransition.spec.js +109 -0
- package/tests/Document.spec.js +232 -0
- package/tests/DocumentBatchTransition.spec.js +109 -0
- package/tests/DocumentTransition.spec.js +97 -0
- package/tests/DocumentsTransitions.spec.js +705 -0
- package/tests/Identity.spec.js +113 -0
- package/tests/IdentityPublicKey.spec.js +132 -0
- package/tests/PrivateKey.spec.js +73 -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/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/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/{cbor-conversation → cbor_conversation}/src/lib.rs +0 -0
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
use dpp::identity::SecurityLevel;
|
|
2
|
+
use wasm_bindgen::JsValue;
|
|
2
3
|
use wasm_bindgen::prelude::wasm_bindgen;
|
|
3
4
|
|
|
4
5
|
#[wasm_bindgen(js_name = SecurityLevel)]
|
|
@@ -9,6 +10,51 @@ pub enum SecurityLevelWASM {
|
|
|
9
10
|
MEDIUM = 3,
|
|
10
11
|
}
|
|
11
12
|
|
|
13
|
+
impl TryFrom<JsValue> for SecurityLevelWASM {
|
|
14
|
+
type Error = JsValue;
|
|
15
|
+
fn try_from(value: JsValue) -> Result<Self, Self::Error> {
|
|
16
|
+
match value.is_string() {
|
|
17
|
+
true => match value.as_string() {
|
|
18
|
+
None => Err(JsValue::from("cannot read value from enum")),
|
|
19
|
+
Some(enum_val) => match enum_val.to_lowercase().as_str() {
|
|
20
|
+
"master" => Ok(SecurityLevelWASM::MASTER),
|
|
21
|
+
"critical" => Ok(SecurityLevelWASM::CRITICAL),
|
|
22
|
+
"high" => Ok(SecurityLevelWASM::HIGH),
|
|
23
|
+
"medium" => Ok(SecurityLevelWASM::MEDIUM),
|
|
24
|
+
_ => Err(JsValue::from(format!(
|
|
25
|
+
"unsupported security level value ({})",
|
|
26
|
+
enum_val
|
|
27
|
+
))),
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
false => match value.as_f64() {
|
|
31
|
+
None => Err(JsValue::from("cannot read value from enum")),
|
|
32
|
+
Some(enum_val) => match enum_val as u8 {
|
|
33
|
+
0 => Ok(SecurityLevelWASM::MASTER),
|
|
34
|
+
1 => Ok(SecurityLevelWASM::CRITICAL),
|
|
35
|
+
2 => Ok(SecurityLevelWASM::HIGH),
|
|
36
|
+
3 => Ok(SecurityLevelWASM::MEDIUM),
|
|
37
|
+
_ => Err(JsValue::from(format!(
|
|
38
|
+
"unsupported security level value ({})",
|
|
39
|
+
enum_val
|
|
40
|
+
))),
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
impl From<SecurityLevelWASM> for String {
|
|
48
|
+
fn from(level: SecurityLevelWASM) -> String {
|
|
49
|
+
match level {
|
|
50
|
+
SecurityLevelWASM::MASTER => String::from("MASTER"),
|
|
51
|
+
SecurityLevelWASM::CRITICAL => String::from("CRITICAL"),
|
|
52
|
+
SecurityLevelWASM::HIGH => String::from("HIGH"),
|
|
53
|
+
SecurityLevelWASM::MEDIUM => String::from("MEDIUM"),
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
12
58
|
impl From<SecurityLevelWASM> for SecurityLevel {
|
|
13
59
|
fn from(security_level: SecurityLevelWASM) -> Self {
|
|
14
60
|
match security_level {
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
use dpp::dashcore::network::constants::Network;
|
|
2
|
+
use wasm_bindgen::JsValue;
|
|
3
|
+
use wasm_bindgen::prelude::wasm_bindgen;
|
|
4
|
+
#[wasm_bindgen(js_name = "NetworkWASM")]
|
|
5
|
+
#[allow(non_camel_case_types)]
|
|
6
|
+
pub enum NetworkWASM {
|
|
7
|
+
Mainnet = 0,
|
|
8
|
+
Testnet = 1,
|
|
9
|
+
Devnet = 2,
|
|
10
|
+
Regtest = 3,
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
impl TryFrom<JsValue> for NetworkWASM {
|
|
14
|
+
type Error = JsValue;
|
|
15
|
+
fn try_from(value: JsValue) -> Result<Self, Self::Error> {
|
|
16
|
+
match value.is_string() {
|
|
17
|
+
true => match value.as_string() {
|
|
18
|
+
None => Err(JsValue::from("cannot read value from enum")),
|
|
19
|
+
Some(enum_val) => match enum_val.to_lowercase().as_str() {
|
|
20
|
+
"mainnet" => Ok(NetworkWASM::Mainnet),
|
|
21
|
+
"testnet" => Ok(NetworkWASM::Testnet),
|
|
22
|
+
"devnet" => Ok(NetworkWASM::Devnet),
|
|
23
|
+
"regtest" => Ok(NetworkWASM::Regtest),
|
|
24
|
+
_ => Err(JsValue::from(format!(
|
|
25
|
+
"unsupported network name ({})",
|
|
26
|
+
enum_val
|
|
27
|
+
))),
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
false => match value.as_f64() {
|
|
31
|
+
None => Err(JsValue::from("cannot read value from enum")),
|
|
32
|
+
Some(enum_val) => match enum_val as u8 {
|
|
33
|
+
0 => Ok(NetworkWASM::Mainnet),
|
|
34
|
+
1 => Ok(NetworkWASM::Testnet),
|
|
35
|
+
2 => Ok(NetworkWASM::Devnet),
|
|
36
|
+
3 => Ok(NetworkWASM::Regtest),
|
|
37
|
+
_ => Err(JsValue::from(format!(
|
|
38
|
+
"unsupported network name ({})",
|
|
39
|
+
enum_val
|
|
40
|
+
))),
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
impl From<NetworkWASM> for String {
|
|
48
|
+
fn from(value: NetworkWASM) -> Self {
|
|
49
|
+
match value {
|
|
50
|
+
NetworkWASM::Mainnet => "Mainnet".to_string(),
|
|
51
|
+
NetworkWASM::Testnet => "Testnet".to_string(),
|
|
52
|
+
NetworkWASM::Devnet => "Devnet".to_string(),
|
|
53
|
+
NetworkWASM::Regtest => "Regtest".to_string(),
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
impl From<NetworkWASM> for Network {
|
|
59
|
+
fn from(network: NetworkWASM) -> Self {
|
|
60
|
+
match network {
|
|
61
|
+
NetworkWASM::Mainnet => Network::Dash,
|
|
62
|
+
NetworkWASM::Testnet => Network::Testnet,
|
|
63
|
+
NetworkWASM::Devnet => Network::Devnet,
|
|
64
|
+
NetworkWASM::Regtest => Network::Regtest,
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -7,19 +7,77 @@ use dpp::version::v5::PLATFORM_V5;
|
|
|
7
7
|
use dpp::version::v6::PLATFORM_V6;
|
|
8
8
|
use dpp::version::v7::PLATFORM_V7;
|
|
9
9
|
use dpp::version::v8::PLATFORM_V8;
|
|
10
|
+
use wasm_bindgen::JsValue;
|
|
10
11
|
use wasm_bindgen::prelude::wasm_bindgen;
|
|
11
12
|
|
|
12
13
|
#[wasm_bindgen(js_name = "PlatformVersionWASM")]
|
|
13
14
|
#[allow(non_camel_case_types)]
|
|
14
15
|
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,
|
|
16
|
+
PLATFORM_V1 = 0,
|
|
17
|
+
PLATFORM_V2 = 1,
|
|
18
|
+
PLATFORM_V3 = 2,
|
|
19
|
+
PLATFORM_V4 = 3,
|
|
20
|
+
PLATFORM_V5 = 4,
|
|
21
|
+
PLATFORM_V6 = 5,
|
|
22
|
+
PLATFORM_V7 = 6,
|
|
23
|
+
PLATFORM_V8 = 7,
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
impl TryFrom<JsValue> for PlatformVersionWASM {
|
|
27
|
+
type Error = JsValue;
|
|
28
|
+
fn try_from(value: JsValue) -> Result<PlatformVersionWASM, Self::Error> {
|
|
29
|
+
match value.is_string() {
|
|
30
|
+
true => match value.as_string() {
|
|
31
|
+
None => Err(JsValue::from("cannot read value from enum")),
|
|
32
|
+
Some(enum_val) => match enum_val.to_lowercase().as_str() {
|
|
33
|
+
"platform_v1" => Ok(PlatformVersionWASM::PLATFORM_V1),
|
|
34
|
+
"platform_v2" => Ok(PlatformVersionWASM::PLATFORM_V2),
|
|
35
|
+
"platform_v3" => Ok(PlatformVersionWASM::PLATFORM_V3),
|
|
36
|
+
"platform_v4" => Ok(PlatformVersionWASM::PLATFORM_V4),
|
|
37
|
+
"platform_v5" => Ok(PlatformVersionWASM::PLATFORM_V5),
|
|
38
|
+
"platform_v6" => Ok(PlatformVersionWASM::PLATFORM_V6),
|
|
39
|
+
"platform_v7" => Ok(PlatformVersionWASM::PLATFORM_V7),
|
|
40
|
+
"platform_v8" => Ok(PlatformVersionWASM::PLATFORM_V8),
|
|
41
|
+
_ => Err(JsValue::from(format!(
|
|
42
|
+
"unknown platform version value: {}",
|
|
43
|
+
enum_val
|
|
44
|
+
))),
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
false => match value.as_f64() {
|
|
48
|
+
None => Err(JsValue::from("cannot read value from enum")),
|
|
49
|
+
Some(enum_val) => match enum_val as u8 {
|
|
50
|
+
0 => Ok(PlatformVersionWASM::PLATFORM_V1),
|
|
51
|
+
1 => Ok(PlatformVersionWASM::PLATFORM_V2),
|
|
52
|
+
2 => Ok(PlatformVersionWASM::PLATFORM_V3),
|
|
53
|
+
3 => Ok(PlatformVersionWASM::PLATFORM_V4),
|
|
54
|
+
4 => Ok(PlatformVersionWASM::PLATFORM_V5),
|
|
55
|
+
5 => Ok(PlatformVersionWASM::PLATFORM_V6),
|
|
56
|
+
6 => Ok(PlatformVersionWASM::PLATFORM_V7),
|
|
57
|
+
7 => Ok(PlatformVersionWASM::PLATFORM_V8),
|
|
58
|
+
_ => Err(JsValue::from(format!(
|
|
59
|
+
"unknown platform version value: {}",
|
|
60
|
+
enum_val
|
|
61
|
+
))),
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
impl From<PlatformVersionWASM> for String {
|
|
69
|
+
fn from(version: PlatformVersionWASM) -> String {
|
|
70
|
+
match version {
|
|
71
|
+
PlatformVersionWASM::PLATFORM_V1 => String::from("PLATFORM_V1"),
|
|
72
|
+
PlatformVersionWASM::PLATFORM_V2 => String::from("PLATFORM_V2"),
|
|
73
|
+
PlatformVersionWASM::PLATFORM_V3 => String::from("PLATFORM_V3"),
|
|
74
|
+
PlatformVersionWASM::PLATFORM_V4 => String::from("PLATFORM_V4"),
|
|
75
|
+
PlatformVersionWASM::PLATFORM_V5 => String::from("PLATFORM_V5"),
|
|
76
|
+
PlatformVersionWASM::PLATFORM_V6 => String::from("PLATFORM_V6"),
|
|
77
|
+
PlatformVersionWASM::PLATFORM_V7 => String::from("PLATFORM_V7"),
|
|
78
|
+
PlatformVersionWASM::PLATFORM_V8 => String::from("PLATFORM_V8"),
|
|
79
|
+
}
|
|
80
|
+
}
|
|
23
81
|
}
|
|
24
82
|
|
|
25
83
|
impl From<PlatformVersionWASM> for PlatformVersion {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[package]
|
|
2
2
|
name = "pshenmic_dpp_identity"
|
|
3
|
-
version =
|
|
3
|
+
version.workspace = true
|
|
4
4
|
edition = "2024"
|
|
5
5
|
|
|
6
6
|
[lib]
|
|
@@ -11,10 +11,5 @@ 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-serialization"
|
|
13
13
|
]}
|
|
14
|
-
|
|
15
|
-
pshenmic_dpp_public_key = { path = "../public_key" }
|
|
14
|
+
pshenmic_dpp_public_key = { path = "../identity_public_key" }
|
|
16
15
|
pshenmic_dpp_utils = { path = "../utils" }
|
|
17
|
-
|
|
18
|
-
[profile.release]
|
|
19
|
-
lto = true
|
|
20
|
-
opt-level = 'z'
|
|
@@ -2,10 +2,12 @@ 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::prelude::IdentityPublicKey;
|
|
5
6
|
use dpp::serialization::{PlatformDeserializable, PlatformSerializable};
|
|
6
7
|
use dpp::version::PlatformVersion;
|
|
7
8
|
use pshenmic_dpp_public_key::IdentityPublicKeyWASM;
|
|
8
|
-
use pshenmic_dpp_utils::WithJsError;
|
|
9
|
+
use pshenmic_dpp_utils::{WithJsError, identifier_from_js_value};
|
|
10
|
+
use std::collections::BTreeMap;
|
|
9
11
|
use wasm_bindgen::JsValue;
|
|
10
12
|
use wasm_bindgen::prelude::wasm_bindgen;
|
|
11
13
|
|
|
@@ -29,10 +31,10 @@ impl IdentityWASM {
|
|
|
29
31
|
}
|
|
30
32
|
|
|
31
33
|
#[wasm_bindgen(js_name = "setId")]
|
|
32
|
-
pub fn set_id(&mut self, js_identifier:
|
|
33
|
-
let identifier =
|
|
34
|
+
pub fn set_id(&mut self, js_identifier: JsValue) -> Result<(), JsValue> {
|
|
35
|
+
let identifier = identifier_from_js_value(&js_identifier)?;
|
|
34
36
|
|
|
35
|
-
self.0.set_id(identifier)
|
|
37
|
+
Ok(self.0.set_id(identifier))
|
|
36
38
|
}
|
|
37
39
|
|
|
38
40
|
#[wasm_bindgen(js_name = "setBalance")]
|
|
@@ -46,17 +48,15 @@ impl IdentityWASM {
|
|
|
46
48
|
}
|
|
47
49
|
|
|
48
50
|
#[wasm_bindgen(js_name = "addPublicKey")]
|
|
49
|
-
pub fn
|
|
50
|
-
self.0.add_public_key(public_key.into());
|
|
51
|
+
pub fn add_public_key(&mut self, public_key: &IdentityPublicKeyWASM) {
|
|
52
|
+
self.0.add_public_key(public_key.clone().into());
|
|
51
53
|
}
|
|
52
54
|
|
|
53
55
|
// GETTERS
|
|
54
56
|
|
|
55
57
|
#[wasm_bindgen(js_name = "getId")]
|
|
56
|
-
pub fn get_id(&self) ->
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
id.to_string(Base58)
|
|
58
|
+
pub fn get_id(&self) -> Vec<u8> {
|
|
59
|
+
self.0.id().to_vec()
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
#[wasm_bindgen(js_name = "getBalance")]
|
|
@@ -76,10 +76,15 @@ impl IdentityWASM {
|
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
#[wasm_bindgen(js_name = "getPublicKeys")]
|
|
79
|
-
pub fn get_public_keys(&self) ->
|
|
80
|
-
let keys = self
|
|
81
|
-
|
|
82
|
-
|
|
79
|
+
pub fn get_public_keys(&self) -> Vec<IdentityPublicKeyWASM> {
|
|
80
|
+
let keys = self
|
|
81
|
+
.0
|
|
82
|
+
.public_keys()
|
|
83
|
+
.iter()
|
|
84
|
+
.map(|(_index, key)| IdentityPublicKeyWASM::from(key.clone()))
|
|
85
|
+
.collect();
|
|
86
|
+
|
|
87
|
+
keys
|
|
83
88
|
}
|
|
84
89
|
|
|
85
90
|
#[wasm_bindgen(js_name = "toBytes")]
|
|
@@ -95,3 +100,9 @@ impl IdentityWASM {
|
|
|
95
100
|
}
|
|
96
101
|
}
|
|
97
102
|
}
|
|
103
|
+
|
|
104
|
+
impl IdentityWASM {
|
|
105
|
+
pub fn get_rs_public_keys(&self) -> BTreeMap<KeyID, IdentityPublicKey> {
|
|
106
|
+
self.0.public_keys().clone()
|
|
107
|
+
}
|
|
108
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[package]
|
|
2
2
|
name = "pshenmic_dpp_public_key"
|
|
3
|
-
version =
|
|
3
|
+
version.workspace = true
|
|
4
4
|
edition = "2024"
|
|
5
5
|
|
|
6
6
|
[lib]
|
|
@@ -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"}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
use dpp::dashcore::Network;
|
|
2
|
+
use dpp::dashcore::secp256k1::hashes::hex::{Case, DisplayHex};
|
|
3
|
+
use dpp::identity::hash::IdentityPublicKeyHashMethodsV0;
|
|
1
4
|
use dpp::identity::identity_public_key::accessors::v0::{
|
|
2
5
|
IdentityPublicKeyGettersV0, IdentityPublicKeySettersV0,
|
|
3
6
|
};
|
|
@@ -9,6 +12,7 @@ use dpp::serialization::{PlatformDeserializable, PlatformSerializable};
|
|
|
9
12
|
use pshenmic_dpp_enums::keys::key_type::KeyTypeWASM;
|
|
10
13
|
use pshenmic_dpp_enums::keys::purpose::PurposeWASM;
|
|
11
14
|
use pshenmic_dpp_enums::keys::security_level::SecurityLevelWASM;
|
|
15
|
+
use pshenmic_dpp_enums::network::NetworkWASM;
|
|
12
16
|
use pshenmic_dpp_utils::WithJsError;
|
|
13
17
|
use wasm_bindgen::JsValue;
|
|
14
18
|
use wasm_bindgen::prelude::wasm_bindgen;
|
|
@@ -34,46 +38,69 @@ impl IdentityPublicKeyWASM {
|
|
|
34
38
|
#[wasm_bindgen(constructor)]
|
|
35
39
|
pub fn new(
|
|
36
40
|
id: u32,
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
41
|
+
js_purpose: JsValue,
|
|
42
|
+
js_security_level: JsValue,
|
|
43
|
+
js_key_type: JsValue,
|
|
40
44
|
read_only: bool,
|
|
41
45
|
binary_data: &str,
|
|
42
46
|
disabled_at: Option<TimestampMillis>,
|
|
43
|
-
) -> Self {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
47
|
+
) -> Result<Self, JsValue> {
|
|
48
|
+
let purpose = PurposeWASM::try_from(js_purpose)?;
|
|
49
|
+
let security_level = SecurityLevelWASM::try_from(js_security_level)?;
|
|
50
|
+
let key_type = KeyTypeWASM::try_from(js_key_type)?;
|
|
51
|
+
|
|
52
|
+
Ok(IdentityPublicKeyWASM(IdentityPublicKey::from(
|
|
53
|
+
IdentityPublicKeyV0 {
|
|
54
|
+
id,
|
|
55
|
+
purpose: Purpose::from(purpose),
|
|
56
|
+
security_level: SecurityLevel::from(security_level),
|
|
57
|
+
contract_bounds: None,
|
|
58
|
+
key_type: KeyType::from(key_type),
|
|
59
|
+
read_only,
|
|
60
|
+
data: BinaryData::from_string(binary_data, Hex).unwrap(),
|
|
61
|
+
disabled_at,
|
|
62
|
+
},
|
|
63
|
+
)))
|
|
54
64
|
}
|
|
55
65
|
}
|
|
56
66
|
|
|
57
67
|
#[wasm_bindgen]
|
|
58
68
|
impl IdentityPublicKeyWASM {
|
|
69
|
+
#[wasm_bindgen(js_name = "validatePrivateKey")]
|
|
70
|
+
pub fn validate_private_key(
|
|
71
|
+
&self,
|
|
72
|
+
js_private_key_bytes: Vec<u8>,
|
|
73
|
+
js_network: JsValue,
|
|
74
|
+
) -> Result<bool, JsValue> {
|
|
75
|
+
let mut private_key_bytes = [0u8; 32];
|
|
76
|
+
let len = js_private_key_bytes.len().min(32);
|
|
77
|
+
private_key_bytes[..len].copy_from_slice(&js_private_key_bytes[..len]);
|
|
78
|
+
|
|
79
|
+
let network = Network::from(NetworkWASM::try_from(js_network)?);
|
|
80
|
+
|
|
81
|
+
self.0
|
|
82
|
+
.validate_private_key_bytes(&private_key_bytes, network)
|
|
83
|
+
.with_js_error()
|
|
84
|
+
}
|
|
85
|
+
|
|
59
86
|
#[wasm_bindgen(js_name = getKeyId)]
|
|
60
87
|
pub fn get_key_id(&self) -> u32 {
|
|
61
88
|
self.0.id()
|
|
62
89
|
}
|
|
63
90
|
|
|
64
91
|
#[wasm_bindgen(js_name = getPurpose)]
|
|
65
|
-
pub fn get_purpose(&self) ->
|
|
66
|
-
PurposeWASM::from(self.0.purpose())
|
|
92
|
+
pub fn get_purpose(&self) -> String {
|
|
93
|
+
PurposeWASM::from(self.0.purpose()).into()
|
|
67
94
|
}
|
|
68
95
|
|
|
69
96
|
#[wasm_bindgen(js_name = getSecurityLevel)]
|
|
70
|
-
pub fn get_security_level(&self) ->
|
|
71
|
-
SecurityLevelWASM::from(self.0.security_level())
|
|
97
|
+
pub fn get_security_level(&self) -> String {
|
|
98
|
+
SecurityLevelWASM::from(self.0.security_level()).into()
|
|
72
99
|
}
|
|
73
100
|
|
|
74
101
|
#[wasm_bindgen(js_name = getKeyType)]
|
|
75
|
-
pub fn get_key_type(&self) ->
|
|
76
|
-
KeyTypeWASM::from(self.0.key_type())
|
|
102
|
+
pub fn get_key_type(&self) -> String {
|
|
103
|
+
KeyTypeWASM::from(self.0.key_type()).into()
|
|
77
104
|
}
|
|
78
105
|
|
|
79
106
|
#[wasm_bindgen(js_name = getReadOnly)]
|
|
@@ -97,19 +124,26 @@ impl IdentityPublicKeyWASM {
|
|
|
97
124
|
}
|
|
98
125
|
|
|
99
126
|
#[wasm_bindgen(js_name = setPurpose)]
|
|
100
|
-
pub fn set_purpose(&mut self, purpose:
|
|
101
|
-
self
|
|
127
|
+
pub fn set_purpose(&mut self, purpose: JsValue) -> Result<(), JsValue> {
|
|
128
|
+
Ok(self
|
|
129
|
+
.0
|
|
130
|
+
.set_purpose(Purpose::from(PurposeWASM::try_from(purpose)?)))
|
|
102
131
|
}
|
|
103
132
|
|
|
104
133
|
#[wasm_bindgen(js_name = setSecurityLevel)]
|
|
105
|
-
pub fn set_security_level(&mut self, security_level:
|
|
106
|
-
self
|
|
107
|
-
.
|
|
134
|
+
pub fn set_security_level(&mut self, security_level: JsValue) -> Result<(), JsValue> {
|
|
135
|
+
Ok(self
|
|
136
|
+
.0
|
|
137
|
+
.set_security_level(SecurityLevel::from(SecurityLevelWASM::try_from(
|
|
138
|
+
security_level,
|
|
139
|
+
)?)))
|
|
108
140
|
}
|
|
109
141
|
|
|
110
142
|
#[wasm_bindgen(js_name = setKeyType)]
|
|
111
|
-
pub fn set_key_type(&mut self, key_type:
|
|
112
|
-
self
|
|
143
|
+
pub fn set_key_type(&mut self, key_type: JsValue) -> Result<(), JsValue> {
|
|
144
|
+
Ok(self
|
|
145
|
+
.0
|
|
146
|
+
.set_key_type(KeyType::from(KeyTypeWASM::try_from(key_type)?)))
|
|
113
147
|
}
|
|
114
148
|
|
|
115
149
|
#[wasm_bindgen(js_name = setReadOnly)]
|
|
@@ -120,6 +154,7 @@ impl IdentityPublicKeyWASM {
|
|
|
120
154
|
#[wasm_bindgen(js_name = setData)]
|
|
121
155
|
pub fn set_data(&mut self, binary_data: &str) {
|
|
122
156
|
let data = BinaryData::from_string(binary_data, Hex).unwrap();
|
|
157
|
+
|
|
123
158
|
self.0.set_data(data)
|
|
124
159
|
}
|
|
125
160
|
|
|
@@ -128,6 +163,18 @@ impl IdentityPublicKeyWASM {
|
|
|
128
163
|
self.0.set_disabled_at(disabled_at)
|
|
129
164
|
}
|
|
130
165
|
|
|
166
|
+
#[wasm_bindgen(js_name = "getPublicKeyHash")]
|
|
167
|
+
pub fn public_key_hash(&self) -> Result<String, JsValue> {
|
|
168
|
+
let hash = self
|
|
169
|
+
.0
|
|
170
|
+
.public_key_hash()
|
|
171
|
+
.with_js_error()
|
|
172
|
+
.map(|slice| slice.to_vec())?
|
|
173
|
+
.to_hex_string(Case::Lower);
|
|
174
|
+
|
|
175
|
+
Ok(hash)
|
|
176
|
+
}
|
|
177
|
+
|
|
131
178
|
#[wasm_bindgen(js_name = toBytes)]
|
|
132
179
|
pub fn to_byes(&self) -> Result<Vec<u8>, JsValue> {
|
|
133
180
|
self.0.serialize_to_bytes().with_js_error()
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[package]
|
|
2
2
|
name = "pshenmic_dpp_identity_transitions"
|
|
3
|
-
version =
|
|
3
|
+
version.workspace = true
|
|
4
4
|
edition = "2024"
|
|
5
5
|
|
|
6
6
|
[lib]
|
|
@@ -12,10 +12,6 @@ dpp = { git = "https://github.com/dashpay/platform", branch = "master", default-
|
|
|
12
12
|
"state-transition-signing"
|
|
13
13
|
]}
|
|
14
14
|
pshenmic_dpp_utils = {path = "../utils"}
|
|
15
|
-
pshenmic_dpp_public_key = {path = "../
|
|
15
|
+
pshenmic_dpp_public_key = {path = "../identity_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"}
|
|
@@ -76,13 +76,15 @@ 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)),
|
|
85
|
-
_ => Err(JsValue::from_str(
|
|
85
|
+
_ => Err(JsValue::from_str(
|
|
86
|
+
&"Invalid state document_transition type)",
|
|
87
|
+
)),
|
|
86
88
|
}
|
|
87
89
|
}
|
|
88
90
|
|
|
@@ -11,6 +11,7 @@ use pshenmic_dpp_enums::keys::key_type::KeyTypeWASM;
|
|
|
11
11
|
use pshenmic_dpp_enums::keys::purpose::PurposeWASM;
|
|
12
12
|
use pshenmic_dpp_enums::keys::security_level::SecurityLevelWASM;
|
|
13
13
|
use pshenmic_dpp_public_key::IdentityPublicKeyWASM;
|
|
14
|
+
use wasm_bindgen::JsValue;
|
|
14
15
|
use wasm_bindgen::prelude::wasm_bindgen;
|
|
15
16
|
|
|
16
17
|
#[wasm_bindgen(js_name = "IdentityPublicKeyInCreationWASM")]
|
|
@@ -57,8 +58,8 @@ impl IdentityPublicKeyInCreationWASM {
|
|
|
57
58
|
security_level: SecurityLevelWASM,
|
|
58
59
|
key_type: KeyTypeWASM,
|
|
59
60
|
read_only: bool,
|
|
60
|
-
binary_data:
|
|
61
|
-
signature:
|
|
61
|
+
binary_data: Vec<u8>,
|
|
62
|
+
signature: Vec<u8>,
|
|
62
63
|
) -> IdentityPublicKeyInCreationWASM {
|
|
63
64
|
IdentityPublicKeyInCreationWASM(IdentityPublicKeyInCreation::V0(
|
|
64
65
|
IdentityPublicKeyInCreationV0 {
|
|
@@ -68,19 +69,19 @@ impl IdentityPublicKeyInCreationWASM {
|
|
|
68
69
|
security_level: SecurityLevel::from(security_level),
|
|
69
70
|
contract_bounds: None,
|
|
70
71
|
read_only,
|
|
71
|
-
data: BinaryData::
|
|
72
|
-
signature: BinaryData::
|
|
72
|
+
data: BinaryData::from(binary_data),
|
|
73
|
+
signature: BinaryData::from(signature),
|
|
73
74
|
},
|
|
74
75
|
))
|
|
75
76
|
}
|
|
76
77
|
|
|
77
78
|
#[wasm_bindgen(js_name = toIdentityPublicKey)]
|
|
78
|
-
pub fn to_identity_public_key(&self) -> IdentityPublicKeyWASM {
|
|
79
|
+
pub fn to_identity_public_key(&self) -> Result<IdentityPublicKeyWASM, JsValue> {
|
|
79
80
|
IdentityPublicKeyWASM::new(
|
|
80
81
|
self.0.id(),
|
|
81
|
-
self.0.purpose()
|
|
82
|
-
self.0.security_level()
|
|
83
|
-
self.0.key_type()
|
|
82
|
+
JsValue::from(PurposeWASM::from(self.0.purpose())),
|
|
83
|
+
JsValue::from(SecurityLevelWASM::from(self.0.security_level())),
|
|
84
|
+
JsValue::from(KeyTypeWASM::from(self.0.key_type())),
|
|
84
85
|
self.0.read_only(),
|
|
85
86
|
self.0.data().to_string(Hex).as_str(),
|
|
86
87
|
None,
|
|
@@ -93,18 +94,18 @@ impl IdentityPublicKeyInCreationWASM {
|
|
|
93
94
|
}
|
|
94
95
|
|
|
95
96
|
#[wasm_bindgen(js_name = getPurpose)]
|
|
96
|
-
pub fn get_purpose(&self) ->
|
|
97
|
-
PurposeWASM::from(self.0.purpose())
|
|
97
|
+
pub fn get_purpose(&self) -> String {
|
|
98
|
+
PurposeWASM::from(self.0.purpose()).into()
|
|
98
99
|
}
|
|
99
100
|
|
|
100
101
|
#[wasm_bindgen(js_name = getSecurityLevel)]
|
|
101
|
-
pub fn get_security_level(&self) ->
|
|
102
|
-
SecurityLevelWASM::from(self.0.security_level())
|
|
102
|
+
pub fn get_security_level(&self) -> String {
|
|
103
|
+
SecurityLevelWASM::from(self.0.security_level()).into()
|
|
103
104
|
}
|
|
104
105
|
|
|
105
106
|
#[wasm_bindgen(js_name = getKeyType)]
|
|
106
|
-
pub fn get_key_type(&self) ->
|
|
107
|
-
KeyTypeWASM::from(self.0.key_type())
|
|
107
|
+
pub fn get_key_type(&self) -> String {
|
|
108
|
+
KeyTypeWASM::from(self.0.key_type()).into()
|
|
108
109
|
}
|
|
109
110
|
|
|
110
111
|
#[wasm_bindgen(js_name = getReadOnly)]
|
|
@@ -123,14 +124,17 @@ impl IdentityPublicKeyInCreationWASM {
|
|
|
123
124
|
}
|
|
124
125
|
|
|
125
126
|
#[wasm_bindgen(js_name = setPurpose)]
|
|
126
|
-
pub fn set_purpose(&mut self,
|
|
127
|
-
|
|
127
|
+
pub fn set_purpose(&mut self, js_purpose: JsValue) -> Result<(), JsValue> {
|
|
128
|
+
let purpose = PurposeWASM::try_from(js_purpose)?;
|
|
129
|
+
Ok(self.0.set_purpose(Purpose::from(purpose)))
|
|
128
130
|
}
|
|
129
131
|
|
|
130
132
|
#[wasm_bindgen(js_name = setSecurityLevel)]
|
|
131
|
-
pub fn set_security_level(&mut self,
|
|
132
|
-
|
|
133
|
-
|
|
133
|
+
pub fn set_security_level(&mut self, js_security_level: JsValue) -> Result<(), JsValue> {
|
|
134
|
+
let security_level = SecurityLevelWASM::try_from(js_security_level)?;
|
|
135
|
+
Ok(self
|
|
136
|
+
.0
|
|
137
|
+
.set_security_level(SecurityLevel::from(security_level)))
|
|
134
138
|
}
|
|
135
139
|
|
|
136
140
|
#[wasm_bindgen(js_name = setReadOnly)]
|
|
@@ -139,8 +143,8 @@ impl IdentityPublicKeyInCreationWASM {
|
|
|
139
143
|
}
|
|
140
144
|
|
|
141
145
|
#[wasm_bindgen(js_name = setData)]
|
|
142
|
-
pub fn set_data(&mut self, binary_data:
|
|
143
|
-
let data = BinaryData::
|
|
146
|
+
pub fn set_data(&mut self, binary_data: Vec<u8>) {
|
|
147
|
+
let data = BinaryData::from(binary_data);
|
|
144
148
|
self.0.set_data(data)
|
|
145
149
|
}
|
|
146
150
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[package]
|
|
2
2
|
name = "pshenmic_dpp_mock_bls"
|
|
3
|
-
version =
|
|
3
|
+
version.workspace = true
|
|
4
4
|
edition = "2024"
|
|
5
5
|
|
|
6
6
|
[lib]
|
|
@@ -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
|
+
]}
|