pshenmic-dpp 1.0.0 → 1.0.1
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/Cargo.lock +54 -17
- package/Cargo.toml +10 -3
- package/README.md +3 -0
- package/dist/wasm/pshenmic_dpp.js +508 -40
- package/package.json +3 -4
- package/packages/cbor-conversation/Cargo.toml +6 -2
- package/packages/cbor-conversation/src/lib.rs +1 -3
- package/packages/document/Cargo.toml +4 -0
- package/packages/document_batch/Cargo.toml +6 -2
- package/packages/document_batch/src/lib.rs +88 -187
- package/packages/enums/Cargo.toml +5 -1
- package/packages/identity/Cargo.toml +17 -0
- package/packages/identity/src/lib.rs +77 -0
- package/packages/identity_transitions/Cargo.toml +21 -0
- package/packages/identity_transitions/src/create_transition/mod.rs +99 -0
- package/packages/identity_transitions/src/create_transition/public_key_in_creation/mod.rs +146 -0
- package/packages/identity_transitions/src/lib.rs +1 -0
- package/packages/mock_bls/Cargo.toml +5 -1
- package/packages/private_key/Cargo.toml +5 -1
- package/packages/private_key/src/lib.rs +14 -17
- package/packages/public_key/Cargo.toml +7 -3
- package/packages/public_key/src/lib.rs +58 -38
- package/packages/state_transition/Cargo.toml +22 -0
- package/packages/state_transition/src/lib.rs +95 -0
- package/packages/utils/Cargo.toml +4 -0
- package/scripts/build.sh +2 -3
- package/src/lib.rs +3 -0
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
use dpp::identity::identity_public_key::v0::IdentityPublicKeyV0;
|
|
2
|
+
use dpp::identity::{IdentityPublicKey, KeyType, Purpose, SecurityLevel};
|
|
3
|
+
use dpp::platform_value::BinaryData;
|
|
4
|
+
use dpp::platform_value::string_encoding::Encoding::Hex;
|
|
5
|
+
use dpp::state_transition::public_key_in_creation::IdentityPublicKeyInCreation;
|
|
6
|
+
use dpp::state_transition::public_key_in_creation::accessors::{
|
|
7
|
+
IdentityPublicKeyInCreationV0Getters, IdentityPublicKeyInCreationV0Setters,
|
|
8
|
+
};
|
|
9
|
+
use dpp::state_transition::public_key_in_creation::v0::IdentityPublicKeyInCreationV0;
|
|
10
|
+
use pshenmic_dpp_enums::keys::key_type::KeyTypeWASM;
|
|
11
|
+
use pshenmic_dpp_enums::keys::purpose::PurposeWASM;
|
|
12
|
+
use pshenmic_dpp_enums::keys::security_level::SecurityLevelWASM;
|
|
13
|
+
use pshenmic_dpp_public_key::IdentityPublicKeyWASM;
|
|
14
|
+
use wasm_bindgen::prelude::wasm_bindgen;
|
|
15
|
+
|
|
16
|
+
#[wasm_bindgen(js_name = "IdentityPublicKeyInCreationWASM")]
|
|
17
|
+
pub struct IdentityPublicKeyInCreationWASM(IdentityPublicKeyInCreation);
|
|
18
|
+
|
|
19
|
+
impl From<IdentityPublicKeyInCreation> for IdentityPublicKeyInCreationWASM {
|
|
20
|
+
fn from(value: IdentityPublicKeyInCreation) -> Self {
|
|
21
|
+
IdentityPublicKeyInCreationWASM(value)
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
impl From<IdentityPublicKeyInCreationWASM> for IdentityPublicKeyInCreation {
|
|
26
|
+
fn from(value: IdentityPublicKeyInCreationWASM) -> Self {
|
|
27
|
+
value.0
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
impl From<IdentityPublicKeyInCreationWASM> for IdentityPublicKey {
|
|
32
|
+
fn from(value: IdentityPublicKeyInCreationWASM) -> Self {
|
|
33
|
+
let contract_bounds = match value.0.contract_bounds() {
|
|
34
|
+
None => None,
|
|
35
|
+
Some(bounds) => Some(bounds.clone()),
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
IdentityPublicKey::V0(IdentityPublicKeyV0 {
|
|
39
|
+
id: value.0.id(),
|
|
40
|
+
purpose: value.0.purpose(),
|
|
41
|
+
security_level: value.0.security_level(),
|
|
42
|
+
contract_bounds,
|
|
43
|
+
key_type: value.0.key_type(),
|
|
44
|
+
read_only: value.0.read_only(),
|
|
45
|
+
data: value.0.data().clone(),
|
|
46
|
+
disabled_at: None,
|
|
47
|
+
})
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
#[wasm_bindgen]
|
|
52
|
+
impl IdentityPublicKeyInCreationWASM {
|
|
53
|
+
#[wasm_bindgen(constructor)]
|
|
54
|
+
pub fn new(
|
|
55
|
+
id: u32,
|
|
56
|
+
purpose: PurposeWASM,
|
|
57
|
+
security_level: SecurityLevelWASM,
|
|
58
|
+
key_type: KeyTypeWASM,
|
|
59
|
+
read_only: bool,
|
|
60
|
+
binary_data: &str,
|
|
61
|
+
signature: &str,
|
|
62
|
+
) -> IdentityPublicKeyInCreationWASM {
|
|
63
|
+
IdentityPublicKeyInCreationWASM(IdentityPublicKeyInCreation::V0(
|
|
64
|
+
IdentityPublicKeyInCreationV0 {
|
|
65
|
+
id,
|
|
66
|
+
key_type: KeyType::from(key_type),
|
|
67
|
+
purpose: Purpose::from(purpose),
|
|
68
|
+
security_level: SecurityLevel::from(security_level),
|
|
69
|
+
contract_bounds: None,
|
|
70
|
+
read_only,
|
|
71
|
+
data: BinaryData::from_string(binary_data, Hex).unwrap(),
|
|
72
|
+
signature: BinaryData::from_string(signature, Hex).unwrap(),
|
|
73
|
+
},
|
|
74
|
+
))
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
#[wasm_bindgen(js_name = toIdentityPublicKey)]
|
|
78
|
+
pub fn to_identity_public_key(&self) -> IdentityPublicKeyWASM {
|
|
79
|
+
IdentityPublicKeyWASM::new(
|
|
80
|
+
self.0.id(),
|
|
81
|
+
self.0.purpose().into(),
|
|
82
|
+
self.0.security_level().into(),
|
|
83
|
+
self.0.key_type().into(),
|
|
84
|
+
self.0.read_only(),
|
|
85
|
+
self.0.data().to_string(Hex).as_str(),
|
|
86
|
+
None,
|
|
87
|
+
)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
#[wasm_bindgen(js_name = getKeyId)]
|
|
91
|
+
pub fn get_key_id(&self) -> u32 {
|
|
92
|
+
self.0.id()
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
#[wasm_bindgen(js_name = getPurpose)]
|
|
96
|
+
pub fn get_purpose(&self) -> PurposeWASM {
|
|
97
|
+
PurposeWASM::from(self.0.purpose())
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
#[wasm_bindgen(js_name = getSecurityLevel)]
|
|
101
|
+
pub fn get_security_level(&self) -> SecurityLevelWASM {
|
|
102
|
+
SecurityLevelWASM::from(self.0.security_level())
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
#[wasm_bindgen(js_name = getKeyType)]
|
|
106
|
+
pub fn get_key_type(&self) -> KeyTypeWASM {
|
|
107
|
+
KeyTypeWASM::from(self.0.key_type())
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
#[wasm_bindgen(js_name = getReadOnly)]
|
|
111
|
+
pub fn get_read_only(&self) -> bool {
|
|
112
|
+
self.0.read_only()
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
#[wasm_bindgen(js_name = getData)]
|
|
116
|
+
pub fn get_data(&self) -> String {
|
|
117
|
+
self.0.data().to_string(Hex)
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
#[wasm_bindgen(js_name = setKeyId)]
|
|
121
|
+
pub fn set_key_id(&mut self, key_id: u32) {
|
|
122
|
+
self.0.set_id(key_id)
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
#[wasm_bindgen(js_name = setPurpose)]
|
|
126
|
+
pub fn set_purpose(&mut self, purpose: PurposeWASM) {
|
|
127
|
+
self.0.set_purpose(Purpose::from(purpose))
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
#[wasm_bindgen(js_name = setSecurityLevel)]
|
|
131
|
+
pub fn set_security_level(&mut self, security_level: SecurityLevelWASM) {
|
|
132
|
+
self.0
|
|
133
|
+
.set_security_level(SecurityLevel::from(security_level))
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
#[wasm_bindgen(js_name = setReadOnly)]
|
|
137
|
+
pub fn set_read_only(&mut self, read_only: bool) {
|
|
138
|
+
self.0.set_read_only(read_only)
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
#[wasm_bindgen(js_name = setData)]
|
|
142
|
+
pub fn set_data(&mut self, binary_data: &str) {
|
|
143
|
+
let data = BinaryData::from_string(binary_data, Hex).unwrap();
|
|
144
|
+
self.0.set_data(data)
|
|
145
|
+
}
|
|
146
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
mod create_transition;
|
|
@@ -10,4 +10,8 @@ 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
|
+
|
|
15
|
+
[profile.release]
|
|
16
|
+
lto = true
|
|
17
|
+
opt-level = 'z'
|
|
@@ -1,28 +1,20 @@
|
|
|
1
1
|
use dpp::dashcore::PrivateKey;
|
|
2
|
+
use wasm_bindgen::JsValue;
|
|
2
3
|
use wasm_bindgen::prelude::wasm_bindgen;
|
|
3
4
|
|
|
4
5
|
#[wasm_bindgen(js_name = "PrivateKeyWASM")]
|
|
5
|
-
pub struct PrivateKeyWASM
|
|
6
|
-
private_key: PrivateKey,
|
|
7
|
-
}
|
|
6
|
+
pub struct PrivateKeyWASM(PrivateKey);
|
|
8
7
|
|
|
9
8
|
#[wasm_bindgen]
|
|
10
9
|
impl PrivateKeyWASM {
|
|
11
10
|
#[wasm_bindgen(js_name = "new")]
|
|
12
|
-
pub fn new(wif: &str) -> Self {
|
|
13
|
-
let pk = PrivateKey::from_wif(wif).
|
|
11
|
+
pub fn new(wif: &str) -> Result<Self, JsValue> {
|
|
12
|
+
let pk = PrivateKey::from_wif(wif).map_err(|err| JsValue::from_str(&*err.to_string()));
|
|
14
13
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
impl PrivateKeyWASM {
|
|
20
|
-
pub fn get_key(&self) -> PrivateKey {
|
|
21
|
-
self.private_key
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
pub fn get_key_inner(&self) -> [u8; 32] {
|
|
25
|
-
self.private_key.inner.secret_bytes()
|
|
14
|
+
match pk {
|
|
15
|
+
Ok(pk) => Ok(PrivateKeyWASM(pk)),
|
|
16
|
+
Err(err) => Err(err),
|
|
17
|
+
}
|
|
26
18
|
}
|
|
27
19
|
}
|
|
28
20
|
|
|
@@ -30,6 +22,11 @@ impl PrivateKeyWASM {
|
|
|
30
22
|
impl PrivateKeyWASM {
|
|
31
23
|
#[wasm_bindgen(js_name = "getKeyWIF")]
|
|
32
24
|
pub fn get_key_wif(&self) -> String {
|
|
33
|
-
self.
|
|
25
|
+
self.0.to_wif()
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
#[wasm_bindgen(js_name = "getKeyBytes")]
|
|
29
|
+
pub fn get_key_bytes(&self) -> Vec<u8> {
|
|
30
|
+
self.0.to_bytes()
|
|
34
31
|
}
|
|
35
32
|
}
|
|
@@ -8,8 +8,12 @@ crate-type = ["cdylib", "lib"]
|
|
|
8
8
|
|
|
9
9
|
[dependencies]
|
|
10
10
|
wasm-bindgen = { version = "=0.2.100", features = ["serde-serialize"] }
|
|
11
|
-
|
|
12
|
-
dpp = { git = "https://github.com/dashpay/platform", branch = "master", features = [
|
|
11
|
+
dpp = { git = "https://github.com/dashpay/platform", branch = "master", default-features = false, features = [
|
|
13
12
|
"identity-value-conversion",
|
|
14
13
|
]}
|
|
15
|
-
pshenmic_dpp_enums = {path = "../enums"}
|
|
14
|
+
pshenmic_dpp_enums = {path = "../enums"}
|
|
15
|
+
pshenmic_dpp_utils = {path = "../utils"}
|
|
16
|
+
|
|
17
|
+
[profile.release]
|
|
18
|
+
lto = true
|
|
19
|
+
opt-level = 'z'
|
|
@@ -5,47 +5,52 @@ use dpp::identity::identity_public_key::v0::IdentityPublicKeyV0;
|
|
|
5
5
|
use dpp::identity::{IdentityPublicKey, KeyType, Purpose, SecurityLevel, TimestampMillis};
|
|
6
6
|
use dpp::platform_value::BinaryData;
|
|
7
7
|
use dpp::platform_value::string_encoding::Encoding::Hex;
|
|
8
|
-
use
|
|
8
|
+
use dpp::serialization::{PlatformDeserializable, PlatformSerializable};
|
|
9
9
|
use pshenmic_dpp_enums::keys::key_type::KeyTypeWASM;
|
|
10
10
|
use pshenmic_dpp_enums::keys::purpose::PurposeWASM;
|
|
11
11
|
use pshenmic_dpp_enums::keys::security_level::SecurityLevelWASM;
|
|
12
|
+
use pshenmic_dpp_utils::WithJsError;
|
|
13
|
+
use wasm_bindgen::JsValue;
|
|
12
14
|
use wasm_bindgen::prelude::wasm_bindgen;
|
|
13
15
|
|
|
16
|
+
#[derive(Clone)]
|
|
14
17
|
#[wasm_bindgen(js_name = IdentityPublicKeyWASM)]
|
|
15
|
-
pub struct IdentityPublicKeyWASM
|
|
16
|
-
|
|
18
|
+
pub struct IdentityPublicKeyWASM(IdentityPublicKey);
|
|
19
|
+
|
|
20
|
+
impl From<IdentityPublicKey> for IdentityPublicKeyWASM {
|
|
21
|
+
fn from(value: IdentityPublicKey) -> Self {
|
|
22
|
+
IdentityPublicKeyWASM(value)
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
impl From<IdentityPublicKeyWASM> for IdentityPublicKey {
|
|
27
|
+
fn from(value: IdentityPublicKeyWASM) -> Self {
|
|
28
|
+
value.0
|
|
29
|
+
}
|
|
17
30
|
}
|
|
18
31
|
|
|
19
32
|
#[wasm_bindgen]
|
|
20
33
|
impl IdentityPublicKeyWASM {
|
|
21
|
-
#[wasm_bindgen]
|
|
34
|
+
#[wasm_bindgen(constructor)]
|
|
22
35
|
pub fn new(
|
|
23
36
|
id: u32,
|
|
24
37
|
purpose: PurposeWASM,
|
|
25
38
|
security_level: SecurityLevelWASM,
|
|
26
39
|
key_type: KeyTypeWASM,
|
|
27
|
-
read_only:
|
|
40
|
+
read_only: bool,
|
|
28
41
|
binary_data: &str,
|
|
29
42
|
disabled_at: Option<TimestampMillis>,
|
|
30
43
|
) -> Self {
|
|
31
|
-
IdentityPublicKeyWASM {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}),
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
impl IdentityPublicKeyWASM {
|
|
47
|
-
pub fn get_key(&self) -> IdentityPublicKey {
|
|
48
|
-
self.public_key.clone()
|
|
44
|
+
IdentityPublicKeyWASM(IdentityPublicKey::from(IdentityPublicKeyV0 {
|
|
45
|
+
id,
|
|
46
|
+
purpose: Purpose::from(purpose),
|
|
47
|
+
security_level: SecurityLevel::from(security_level),
|
|
48
|
+
contract_bounds: None,
|
|
49
|
+
key_type: KeyType::from(key_type),
|
|
50
|
+
read_only: read_only,
|
|
51
|
+
data: BinaryData::from_string(binary_data, Hex).unwrap(),
|
|
52
|
+
disabled_at,
|
|
53
|
+
}))
|
|
49
54
|
}
|
|
50
55
|
}
|
|
51
56
|
|
|
@@ -53,73 +58,88 @@ impl IdentityPublicKeyWASM {
|
|
|
53
58
|
impl IdentityPublicKeyWASM {
|
|
54
59
|
#[wasm_bindgen(js_name = getKeyId)]
|
|
55
60
|
pub fn get_key_id(&self) -> u32 {
|
|
56
|
-
self.
|
|
61
|
+
self.0.id()
|
|
57
62
|
}
|
|
58
63
|
|
|
59
64
|
#[wasm_bindgen(js_name = getPurpose)]
|
|
60
65
|
pub fn get_purpose(&self) -> PurposeWASM {
|
|
61
|
-
PurposeWASM::from(self.
|
|
66
|
+
PurposeWASM::from(self.0.purpose())
|
|
62
67
|
}
|
|
63
68
|
|
|
64
69
|
#[wasm_bindgen(js_name = getSecurityLevel)]
|
|
65
70
|
pub fn get_security_level(&self) -> SecurityLevelWASM {
|
|
66
|
-
SecurityLevelWASM::from(self.
|
|
71
|
+
SecurityLevelWASM::from(self.0.security_level())
|
|
67
72
|
}
|
|
68
73
|
|
|
69
74
|
#[wasm_bindgen(js_name = getKeyType)]
|
|
70
75
|
pub fn get_key_type(&self) -> KeyTypeWASM {
|
|
71
|
-
KeyTypeWASM::from(self.
|
|
76
|
+
KeyTypeWASM::from(self.0.key_type())
|
|
72
77
|
}
|
|
73
78
|
|
|
74
79
|
#[wasm_bindgen(js_name = getReadOnly)]
|
|
75
80
|
pub fn get_read_only(&self) -> bool {
|
|
76
|
-
self.
|
|
81
|
+
self.0.read_only()
|
|
77
82
|
}
|
|
78
83
|
|
|
79
84
|
#[wasm_bindgen(js_name = getData)]
|
|
80
85
|
pub fn get_data(&self) -> String {
|
|
81
|
-
self.
|
|
86
|
+
self.0.data().to_string(Hex)
|
|
82
87
|
}
|
|
83
88
|
|
|
84
89
|
#[wasm_bindgen(js_name = getDisabledAt)]
|
|
85
90
|
pub fn get_disabled_at(&self) -> Option<u64> {
|
|
86
|
-
self.
|
|
91
|
+
self.0.disabled_at()
|
|
87
92
|
}
|
|
88
93
|
|
|
89
94
|
#[wasm_bindgen(js_name = setKeyId)]
|
|
90
95
|
pub fn set_key_id(&mut self, key_id: u32) {
|
|
91
|
-
self.
|
|
96
|
+
self.0.set_id(key_id)
|
|
92
97
|
}
|
|
93
98
|
|
|
94
99
|
#[wasm_bindgen(js_name = setPurpose)]
|
|
95
100
|
pub fn set_purpose(&mut self, purpose: PurposeWASM) {
|
|
96
|
-
self.
|
|
101
|
+
self.0.set_purpose(Purpose::from(purpose))
|
|
97
102
|
}
|
|
98
103
|
|
|
99
104
|
#[wasm_bindgen(js_name = setSecurityLevel)]
|
|
100
105
|
pub fn set_security_level(&mut self, security_level: SecurityLevelWASM) {
|
|
101
|
-
self.
|
|
106
|
+
self.0
|
|
102
107
|
.set_security_level(SecurityLevel::from(security_level))
|
|
103
108
|
}
|
|
104
109
|
|
|
105
110
|
#[wasm_bindgen(js_name = setKeyType)]
|
|
106
111
|
pub fn set_key_type(&mut self, key_type: KeyTypeWASM) {
|
|
107
|
-
self.
|
|
112
|
+
self.0.set_key_type(KeyType::from(key_type))
|
|
108
113
|
}
|
|
109
114
|
|
|
110
115
|
#[wasm_bindgen(js_name = setReadOnly)]
|
|
111
|
-
pub fn set_read_only(&mut self, read_only:
|
|
112
|
-
self.
|
|
116
|
+
pub fn set_read_only(&mut self, read_only: bool) {
|
|
117
|
+
self.0.set_read_only(read_only)
|
|
113
118
|
}
|
|
114
119
|
|
|
115
120
|
#[wasm_bindgen(js_name = setData)]
|
|
116
121
|
pub fn set_data(&mut self, binary_data: &str) {
|
|
117
122
|
let data = BinaryData::from_string(binary_data, Hex).unwrap();
|
|
118
|
-
self.
|
|
123
|
+
self.0.set_data(data)
|
|
119
124
|
}
|
|
120
125
|
|
|
121
126
|
#[wasm_bindgen(js_name = setDisabledAt)]
|
|
122
127
|
pub fn set_disabled_at(&mut self, disabled_at: u64) {
|
|
123
|
-
self.
|
|
128
|
+
self.0.set_disabled_at(disabled_at)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
#[wasm_bindgen(js_name = toBuffer)]
|
|
132
|
+
pub fn to_buffer(&self) -> Result<Vec<u8>, JsValue> {
|
|
133
|
+
self.0.serialize_to_bytes().with_js_error()
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
#[wasm_bindgen(js_name = fromBuffer)]
|
|
137
|
+
pub fn from_buffer(buffer: Vec<u8>) -> Result<IdentityPublicKeyWASM, JsValue> {
|
|
138
|
+
let rs_pk = IdentityPublicKey::deserialize_from_bytes(buffer.as_slice()).with_js_error();
|
|
139
|
+
|
|
140
|
+
match rs_pk {
|
|
141
|
+
Ok(pk) => Ok(IdentityPublicKeyWASM(pk)),
|
|
142
|
+
Err(e) => Err(e),
|
|
143
|
+
}
|
|
124
144
|
}
|
|
125
145
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
[package]
|
|
2
|
+
name = "pshenmic_dpp_state_transition"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
edition = "2024"
|
|
5
|
+
|
|
6
|
+
[lib]
|
|
7
|
+
crate-type = ["cdylib", "lib"]
|
|
8
|
+
|
|
9
|
+
[dependencies]
|
|
10
|
+
wasm-bindgen = { version = "=0.2.100", features = ["serde-serialize"] }
|
|
11
|
+
pshenmic_dpp_public_key = {path = "../public_key"}
|
|
12
|
+
pshenmic_dpp_private_key = {path = "../private_key"}
|
|
13
|
+
pshenmic_dpp_utils = {path = "../utils"}
|
|
14
|
+
pshenmic_dpp_mock_bls = {path = "../mock_bls"}
|
|
15
|
+
pshenmic_dpp_enums = {path = "../enums"}
|
|
16
|
+
dpp = { git = "https://github.com/dashpay/platform", branch = "master", default-features = false, features = [
|
|
17
|
+
"state-transition-signing"
|
|
18
|
+
]}
|
|
19
|
+
|
|
20
|
+
[profile.release]
|
|
21
|
+
lto = true
|
|
22
|
+
opt-level = 'z'
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
use dpp::identity::KeyType;
|
|
2
|
+
use dpp::serialization::{PlatformDeserializable, PlatformSerializable};
|
|
3
|
+
use dpp::state_transition::StateTransition;
|
|
4
|
+
use pshenmic_dpp_enums::keys::key_type::KeyTypeWASM;
|
|
5
|
+
use pshenmic_dpp_mock_bls::MockBLS;
|
|
6
|
+
use pshenmic_dpp_private_key::PrivateKeyWASM;
|
|
7
|
+
use pshenmic_dpp_public_key::IdentityPublicKeyWASM;
|
|
8
|
+
use pshenmic_dpp_utils::WithJsError;
|
|
9
|
+
use wasm_bindgen::JsValue;
|
|
10
|
+
use wasm_bindgen::prelude::wasm_bindgen;
|
|
11
|
+
|
|
12
|
+
#[wasm_bindgen(js_name = "StateTransitionWASM")]
|
|
13
|
+
pub struct StateTransitionWASM(StateTransition);
|
|
14
|
+
|
|
15
|
+
impl From<StateTransition> for StateTransitionWASM {
|
|
16
|
+
fn from(transition: StateTransition) -> Self {
|
|
17
|
+
StateTransitionWASM(transition)
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
impl From<StateTransitionWASM> for StateTransition {
|
|
22
|
+
fn from(transition: StateTransitionWASM) -> Self {
|
|
23
|
+
transition.0
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
#[wasm_bindgen]
|
|
28
|
+
impl StateTransitionWASM {
|
|
29
|
+
#[wasm_bindgen(js_name=sign)]
|
|
30
|
+
pub fn sign(
|
|
31
|
+
&mut self,
|
|
32
|
+
private_key: PrivateKeyWASM,
|
|
33
|
+
public_key: IdentityPublicKeyWASM,
|
|
34
|
+
) -> Result<JsValue, JsValue> {
|
|
35
|
+
let sig = self.0.sign(
|
|
36
|
+
&public_key.into(),
|
|
37
|
+
private_key.get_key_bytes().as_slice(),
|
|
38
|
+
&MockBLS {},
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
let bytes = match sig {
|
|
42
|
+
Ok(_sig) => {
|
|
43
|
+
self.0.set_signature(self.0.signature().clone());
|
|
44
|
+
self.0
|
|
45
|
+
.set_signature_public_key_id(self.0.signature_public_key_id().unwrap());
|
|
46
|
+
self.0.serialize_to_bytes()
|
|
47
|
+
}
|
|
48
|
+
Err(e) => wasm_bindgen::throw_str(&e.to_string()),
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
match bytes {
|
|
52
|
+
Ok(bytes) => Ok(JsValue::from(bytes.clone())),
|
|
53
|
+
Err(e) => Ok(JsValue::from_str(&format!("{}", e))),
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
#[wasm_bindgen(js_name=signByPrivateKey)]
|
|
58
|
+
pub fn sign_by_private_key(
|
|
59
|
+
&mut self,
|
|
60
|
+
private_key: PrivateKeyWASM,
|
|
61
|
+
key_type: KeyTypeWASM,
|
|
62
|
+
) -> JsValue {
|
|
63
|
+
let _sig = self
|
|
64
|
+
.0
|
|
65
|
+
.sign_by_private_key(
|
|
66
|
+
&private_key.get_key_bytes().as_slice(),
|
|
67
|
+
KeyType::from(key_type),
|
|
68
|
+
&MockBLS {},
|
|
69
|
+
)
|
|
70
|
+
.with_js_error();
|
|
71
|
+
|
|
72
|
+
let bytes = self.0.serialize_to_bytes().with_js_error();
|
|
73
|
+
|
|
74
|
+
match bytes {
|
|
75
|
+
Ok(bytes) => JsValue::from(bytes.clone()),
|
|
76
|
+
Err(err) => err,
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
#[wasm_bindgen(js_name=toBuffer)]
|
|
81
|
+
pub fn to_buffer(&self) -> Result<JsValue, JsValue> {
|
|
82
|
+
let bytes = self.0.serialize_to_bytes().expect("Serialization failed");
|
|
83
|
+
|
|
84
|
+
Ok(JsValue::from(bytes.clone()))
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
pub fn from_buffer(buffer: Vec<u8>) -> Result<StateTransitionWASM, JsValue> {
|
|
88
|
+
let st = StateTransition::deserialize_from_bytes(buffer.as_slice());
|
|
89
|
+
|
|
90
|
+
match st {
|
|
91
|
+
Err(err) => Err(JsValue::from_str(err.to_string().as_str())),
|
|
92
|
+
Ok(transition) => Ok(StateTransitionWASM(transition)),
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
@@ -18,3 +18,7 @@ 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
20
|
itertools = { version = "0.13" }
|
|
21
|
+
|
|
22
|
+
[profile.release]
|
|
23
|
+
lto = true
|
|
24
|
+
opt-level = 'z'
|
package/scripts/build.sh
CHANGED
|
@@ -4,9 +4,8 @@
|
|
|
4
4
|
TARGET=wasm32-unknown-unknown
|
|
5
5
|
|
|
6
6
|
OUTPUT_DIR="${PWD}/wasm"
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
PROFILE=debug
|
|
7
|
+
PROFILE_ARG="--release"
|
|
8
|
+
PROFILE=release
|
|
10
9
|
|
|
11
10
|
OUTPUT_FILE="${PWD}/wasm/pshenmic_dpp_bg.wasm"
|
|
12
11
|
|