pshenmic-dpp 1.0.4 → 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 +79 -31
- package/Cargo.toml +20 -17
- package/README.md +66 -23
- package/babel.config.json +19 -0
- package/dist/wasm/pshenmic_dpp.js +2487 -355
- package/dist/wasm/pshenmic_dpp_bg.js +1 -1
- package/package.json +13 -6
- package/packages/cbor_conversation/Cargo.toml +1 -1
- package/packages/data_contract/Cargo.toml +2 -2
- package/packages/data_contract/src/lib.rs +195 -23
- package/packages/data_contract_transitions/Cargo.toml +1 -1
- 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 +1 -1
- package/packages/document/src/lib.rs +1 -1
- package/packages/document/src/methods/mod.rs +370 -2
- package/packages/{document_batch → documents_batch}/Cargo.toml +6 -4
- 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 +3 -3
- 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 +3 -4
- package/packages/identity/src/lib.rs +25 -14
- package/packages/{public_key → identity_public_key}/Cargo.toml +1 -1
- package/packages/{public_key → identity_public_key}/src/lib.rs +74 -27
- package/packages/identity_transitions/Cargo.toml +2 -2
- package/packages/identity_transitions/src/create_transition/mod.rs +3 -1
- package/packages/identity_transitions/src/create_transition/public_key_in_creation/mod.rs +25 -21
- package/packages/mock_bls/Cargo.toml +1 -1
- package/packages/private_key/Cargo.toml +3 -2
- package/packages/private_key/src/lib.rs +44 -6
- package/packages/state_transition/Cargo.toml +5 -4
- package/packages/state_transition/src/lib.rs +101 -36
- package/packages/utils/Cargo.toml +1 -2
- package/packages/utils/src/lib.rs +17 -15
- package/scripts/build-js.sh +6 -5
- package/scripts/build.sh +22 -1
- package/src/lib.rs +7 -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
|
@@ -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,6 +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
|
-
|
|
16
|
-
pshenmic_dpp_utils = { path = "../utils" }
|
|
14
|
+
pshenmic_dpp_public_key = { path = "../identity_public_key" }
|
|
15
|
+
pshenmic_dpp_utils = { path = "../utils" }
|
|
@@ -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,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,6 +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
17
|
pshenmic_dpp_enums = {path = "../enums"}
|
|
@@ -82,7 +82,9 @@ impl IdentityCreateTransitionWASM {
|
|
|
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_private_key"
|
|
3
|
-
version =
|
|
3
|
+
version.workspace = true
|
|
4
4
|
edition = "2024"
|
|
5
5
|
|
|
6
6
|
[lib]
|
|
@@ -10,4 +10,5 @@ crate-type = ["cdylib", "lib"]
|
|
|
10
10
|
wasm-bindgen = { version = "=0.2.100", features = ["serde-serialize"] }
|
|
11
11
|
dpp = { git = "https://github.com/dashpay/platform", branch = "master", default-features = false, features = [
|
|
12
12
|
"identity-value-conversion",
|
|
13
|
-
]}
|
|
13
|
+
]}
|
|
14
|
+
pshenmic_dpp_enums = {path = "../enums"}
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
use dpp::dashcore::PrivateKey;
|
|
2
|
+
use dpp::dashcore::hashes::hex::FromHex;
|
|
3
|
+
use dpp::dashcore::key::Secp256k1;
|
|
4
|
+
use dpp::dashcore::secp256k1::hashes::hex::{Case, DisplayHex};
|
|
5
|
+
use pshenmic_dpp_enums::network::NetworkWASM;
|
|
2
6
|
use wasm_bindgen::JsValue;
|
|
3
7
|
use wasm_bindgen::prelude::wasm_bindgen;
|
|
4
8
|
|
|
@@ -7,8 +11,8 @@ pub struct PrivateKeyWASM(PrivateKey);
|
|
|
7
11
|
|
|
8
12
|
#[wasm_bindgen]
|
|
9
13
|
impl PrivateKeyWASM {
|
|
10
|
-
#[wasm_bindgen(
|
|
11
|
-
pub fn
|
|
14
|
+
#[wasm_bindgen(js_name = "fromWIF")]
|
|
15
|
+
pub fn from_wif(wif: &str) -> Result<Self, JsValue> {
|
|
12
16
|
let pk = PrivateKey::from_wif(wif).map_err(|err| JsValue::from_str(&*err.to_string()));
|
|
13
17
|
|
|
14
18
|
match pk {
|
|
@@ -16,17 +20,51 @@ impl PrivateKeyWASM {
|
|
|
16
20
|
Err(err) => Err(err),
|
|
17
21
|
}
|
|
18
22
|
}
|
|
23
|
+
|
|
24
|
+
#[wasm_bindgen(js_name = "fromBytes")]
|
|
25
|
+
pub fn from_bytes(bytes: Vec<u8>, js_network: JsValue) -> Result<Self, JsValue> {
|
|
26
|
+
let network = NetworkWASM::try_from(js_network)?;
|
|
27
|
+
|
|
28
|
+
let pk = PrivateKey::from_slice(bytes.as_slice(), network.into())
|
|
29
|
+
.map_err(|err| JsValue::from_str(&*err.to_string()))?;
|
|
30
|
+
|
|
31
|
+
Ok(PrivateKeyWASM(pk))
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
#[wasm_bindgen(js_name = "fromHex")]
|
|
35
|
+
pub fn from_hex(hex_key: &str, js_network: JsValue) -> Result<Self, JsValue> {
|
|
36
|
+
let network = NetworkWASM::try_from(js_network)?;
|
|
37
|
+
|
|
38
|
+
let bytes = Vec::from_hex(hex_key).map_err(|err| JsValue::from(err.to_string()))?;
|
|
39
|
+
|
|
40
|
+
let pk = PrivateKey::from_slice(bytes.as_slice(), network.into())
|
|
41
|
+
.map_err(|err| JsValue::from_str(&*err.to_string()))?;
|
|
42
|
+
|
|
43
|
+
Ok(PrivateKeyWASM(pk))
|
|
44
|
+
}
|
|
19
45
|
}
|
|
20
46
|
|
|
21
47
|
#[wasm_bindgen]
|
|
22
48
|
impl PrivateKeyWASM {
|
|
23
|
-
#[wasm_bindgen(js_name = "
|
|
24
|
-
pub fn
|
|
49
|
+
#[wasm_bindgen(js_name = "getWIF")]
|
|
50
|
+
pub fn get_wif(&self) -> String {
|
|
25
51
|
self.0.to_wif()
|
|
26
52
|
}
|
|
27
53
|
|
|
28
|
-
#[wasm_bindgen(js_name = "
|
|
29
|
-
pub fn
|
|
54
|
+
#[wasm_bindgen(js_name = "getBytes")]
|
|
55
|
+
pub fn get_bytes(&self) -> Vec<u8> {
|
|
30
56
|
self.0.to_bytes()
|
|
31
57
|
}
|
|
58
|
+
|
|
59
|
+
#[wasm_bindgen(js_name = "getHex")]
|
|
60
|
+
pub fn get_hex(&self) -> String {
|
|
61
|
+
self.0.to_bytes().to_hex_string(Case::Upper)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
#[wasm_bindgen(js_name = "getPublicKeyHash")]
|
|
65
|
+
pub fn get_public_key_hash(&self) -> String {
|
|
66
|
+
let secp = Secp256k1::new();
|
|
67
|
+
|
|
68
|
+
self.0.public_key(&secp).pubkey_hash().to_hex()
|
|
69
|
+
}
|
|
32
70
|
}
|
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
[package]
|
|
2
2
|
name = "pshenmic_dpp_state_transition"
|
|
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"] }
|
|
11
|
-
pshenmic_dpp_public_key = {path = "../
|
|
10
|
+
wasm-bindgen = { version = "=0.2.100", features = ["serde-serialize"], default-features = false }
|
|
11
|
+
pshenmic_dpp_public_key = {path = "../identity_public_key" }
|
|
12
12
|
pshenmic_dpp_private_key = {path = "../private_key"}
|
|
13
13
|
pshenmic_dpp_utils = {path = "../utils"}
|
|
14
14
|
pshenmic_dpp_mock_bls = {path = "../mock_bls"}
|
|
15
15
|
pshenmic_dpp_enums = {path = "../enums"}
|
|
16
16
|
dpp = { git = "https://github.com/dashpay/platform", branch = "master", default-features = false, features = [
|
|
17
17
|
"state-transition-signing"
|
|
18
|
-
]}
|
|
18
|
+
]}
|
|
19
|
+
sha2 = "0.10.8"
|