Skip to content

Commit e6bda11

Browse files
committed
chore(dpp): fix build errors and some lint warnings
1 parent ab74355 commit e6bda11

File tree

4 files changed

+53
-72
lines changed

4 files changed

+53
-72
lines changed

packages/rs-dpp/src/errors/protocol_error.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use dashcore::blsful::BlsError;
21
use thiserror::Error;
32

43
use crate::consensus::basic::state_transition::InvalidStateTransitionTypeError;
@@ -249,9 +248,10 @@ pub enum ProtocolError {
249248
#[error("invalid cbor error: {0}")]
250249
InvalidCBOR(String),
251250

252-
/// Invalid CBOR error
251+
/// BLS signature error
252+
#[cfg(feature = "bls-signatures")]
253253
#[error(transparent)]
254-
BlsError(#[from] BlsError),
254+
BlsError(#[from] dashcore::blsful::BlsError),
255255
}
256256

257257
impl From<&str> for ProtocolError {

packages/rs-dpp/src/identity/identity_public_key/key_type.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,25 @@ use dashcore::secp256k1::rand::rngs::StdRng as EcdsaRng;
88
#[cfg(feature = "random-public-keys")]
99
use dashcore::secp256k1::rand::SeedableRng;
1010
use dashcore::secp256k1::Secp256k1;
11-
use dashcore::{blsful, ed25519_dalek, Network};
11+
use dashcore::Network;
1212
use itertools::Itertools;
1313
use lazy_static::lazy_static;
1414

15-
use crate::bls_signatures::{Bls12381G2Impl, BlsError};
1615
use crate::fee::Credits;
1716
use crate::version::PlatformVersion;
18-
use crate::{bls_signatures, ProtocolError};
17+
use crate::ProtocolError;
1918
#[cfg(feature = "random-public-keys")]
2019
use rand::rngs::StdRng;
2120
#[cfg(feature = "random-public-keys")]
2221
use rand::Rng;
2322
use serde_repr::{Deserialize_repr, Serialize_repr};
2423
use std::collections::HashMap;
2524
use std::convert::TryFrom;
25+
#[cfg(feature = "bls-signatures")]
26+
use {
27+
crate::bls_signatures::{self as bls_signatures, Bls12381G2Impl, BlsError},
28+
dashcore::{blsful, ed25519_dalek},
29+
};
2630

2731
#[allow(non_camel_case_types)]
2832
#[repr(u8)]
@@ -245,19 +249,17 @@ impl KeyType {
245249
KeyType::EDDSA_25519_HASH160 => {
246250
#[cfg(feature = "ed25519-dalek")]
247251
{
248-
let key_pair = ed25519_dalek::SigningKey::from_bytes(&private_key_bytes);
252+
let key_pair = ed25519_dalek::SigningKey::from_bytes(private_key_bytes);
249253
Ok(ripemd160_sha256(key_pair.verifying_key().to_bytes().as_slice()).to_vec())
250254
}
251255
#[cfg(not(feature = "ed25519-dalek"))]
252256
return Err(ProtocolError::NotSupported(
253257
"Converting a private key to a eddsa hash 160 is not supported without the ed25519-dalek feature".to_string(),
254258
));
255259
}
256-
KeyType::BIP13_SCRIPT_HASH => {
257-
return Err(ProtocolError::NotSupported(
258-
"Converting a private key to a script hash is not supported".to_string(),
259-
));
260-
}
260+
KeyType::BIP13_SCRIPT_HASH => Err(ProtocolError::NotSupported(
261+
"Converting a private key to a script hash is not supported".to_string(),
262+
)),
261263
}
262264
}
263265

packages/rs-dpp/src/identity/identity_public_key/v0/methods/mod.rs

Lines changed: 38 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1-
#[cfg(feature = "bls-signatures")]
2-
use crate::bls_signatures;
31
use crate::identity::identity_public_key::methods::hash::IdentityPublicKeyHashMethodsV0;
42
use crate::identity::identity_public_key::v0::IdentityPublicKeyV0;
53
use crate::identity::KeyType;
64
use crate::util::hash::ripemd160_sha256;
75
use crate::ProtocolError;
86
use anyhow::anyhow;
9-
use dashcore::blsful::Bls12381G2Impl;
107
use dashcore::hashes::Hash;
118
use dashcore::key::Secp256k1;
129
use dashcore::secp256k1::SecretKey;
13-
use dashcore::{ed25519_dalek, Network, PublicKey as ECDSAPublicKey};
10+
use dashcore::{Network, PublicKey as ECDSAPublicKey};
1411
use platform_value::Bytes20;
12+
#[cfg(feature = "bls-signatures")]
13+
use {
14+
crate::bls_signatures,
15+
dashcore::{blsful::Bls12381G2Impl, ed25519_dalek},
16+
};
1517

1618
impl IdentityPublicKeyHashMethodsV0 for IdentityPublicKeyV0 {
1719
/// Get the original public key hash
@@ -80,7 +82,7 @@ impl IdentityPublicKeyHashMethodsV0 for IdentityPublicKeyV0 {
8082
}
8183
let private_key = private_key.expect("expected private key");
8284

83-
Ok(&private_key.public_key().0.to_compressed() == self.data.as_slice())
85+
Ok(private_key.public_key().0.to_compressed() == self.data.as_slice())
8486
}
8587
#[cfg(not(feature = "bls-signatures"))]
8688
return Err(ProtocolError::NotSupported(
@@ -104,7 +106,7 @@ impl IdentityPublicKeyHashMethodsV0 for IdentityPublicKeyV0 {
104106
KeyType::EDDSA_25519_HASH160 => {
105107
#[cfg(feature = "ed25519-dalek")]
106108
{
107-
let key_pair = ed25519_dalek::SigningKey::from_bytes(&private_key_bytes);
109+
let key_pair = ed25519_dalek::SigningKey::from_bytes(private_key_bytes);
108110
Ok(
109111
ripemd160_sha256(key_pair.verifying_key().to_bytes().as_slice()).as_slice()
110112
== self.data.as_slice(),
@@ -115,11 +117,9 @@ impl IdentityPublicKeyHashMethodsV0 for IdentityPublicKeyV0 {
115117
"Converting a private key to a eddsa hash 160 is not supported without the ed25519-dalek feature".to_string(),
116118
));
117119
}
118-
KeyType::BIP13_SCRIPT_HASH => {
119-
return Err(ProtocolError::NotSupported(
120-
"Converting a private key to a script hash is not supported".to_string(),
121-
));
122-
}
120+
KeyType::BIP13_SCRIPT_HASH => Err(ProtocolError::NotSupported(
121+
"Converting a private key to a script hash is not supported".to_string(),
122+
)),
123123
}
124124
}
125125
}
@@ -140,10 +140,9 @@ mod tests {
140140
let (public_key_data, secret_key) = KeyType::BLS12_381
141141
.random_public_and_private_key_data(&mut rng, PlatformVersion::latest())
142142
.expect("expected to get keys");
143-
let decoded_secret_key = dashcore::blsful::SecretKey::<Bls12381G2Impl>::from_be_bytes(
144-
&secret_key.try_into().unwrap(),
145-
)
146-
.expect("expected to get secret key");
143+
let decoded_secret_key =
144+
dashcore::blsful::SecretKey::<Bls12381G2Impl>::from_be_bytes(&secret_key)
145+
.expect("expected to get secret key");
147146
let public_key = decoded_secret_key.public_key();
148147
let decoded_public_key_data = public_key.0.to_compressed();
149148
assert_eq!(
@@ -158,10 +157,9 @@ mod tests {
158157
let (_, secret_key) = KeyType::BLS12_381
159158
.random_public_and_private_key_data(&mut rng, PlatformVersion::latest())
160159
.expect("expected to get keys");
161-
let decoded_secret_key = dashcore::blsful::SecretKey::<Bls12381G2Impl>::from_be_bytes(
162-
&secret_key.try_into().unwrap(),
163-
)
164-
.expect("expected to get secret key");
160+
let decoded_secret_key =
161+
dashcore::blsful::SecretKey::<Bls12381G2Impl>::from_be_bytes(&secret_key)
162+
.expect("expected to get secret key");
165163
let signature = decoded_secret_key
166164
.sign(SignatureSchemes::Basic, b"hello")
167165
.expect("expected to sign");
@@ -184,7 +182,7 @@ mod tests {
184182
// Test for ECDSA_SECP256K1
185183
let key_type = KeyType::ECDSA_SECP256K1;
186184
let (public_key_data, private_key_data) = key_type
187-
.random_public_and_private_key_data(&mut rng, &platform_version)
185+
.random_public_and_private_key_data(&mut rng, platform_version)
188186
.expect("expected to generate random keys");
189187

190188
let identity_public_key = IdentityPublicKeyV0 {
@@ -199,21 +197,15 @@ mod tests {
199197
};
200198

201199
// Validate that the private key matches the public key
202-
assert_eq!(
203-
identity_public_key
204-
.validate_private_key_bytes(&private_key_data, Network::Testnet)
205-
.unwrap(),
206-
true
207-
);
200+
assert!(identity_public_key
201+
.validate_private_key_bytes(&private_key_data, Network::Testnet)
202+
.unwrap(),);
208203

209204
// Test with an invalid private key
210205
let invalid_private_key_bytes = [0u8; 32];
211-
assert_eq!(
212-
identity_public_key
213-
.validate_private_key_bytes(&invalid_private_key_bytes, Network::Testnet)
214-
.unwrap(),
215-
false
216-
);
206+
assert!(!identity_public_key
207+
.validate_private_key_bytes(&invalid_private_key_bytes, Network::Testnet)
208+
.unwrap());
217209
}
218210

219211
#[cfg(all(feature = "random-public-keys", feature = "bls-signatures"))]
@@ -225,7 +217,7 @@ mod tests {
225217
// Test for BLS12_381
226218
let key_type = KeyType::BLS12_381;
227219
let (public_key_data, private_key_data) = key_type
228-
.random_public_and_private_key_data(&mut rng, &platform_version)
220+
.random_public_and_private_key_data(&mut rng, platform_version)
229221
.expect("expected to generate random keys");
230222

231223
let identity_public_key = IdentityPublicKeyV0 {
@@ -240,21 +232,15 @@ mod tests {
240232
};
241233

242234
// Validate that the private key matches the public key
243-
assert_eq!(
244-
identity_public_key
245-
.validate_private_key_bytes(&private_key_data, Network::Testnet)
246-
.unwrap(),
247-
true
248-
);
235+
assert!(identity_public_key
236+
.validate_private_key_bytes(&private_key_data, Network::Testnet)
237+
.unwrap());
249238

250239
// Test with an invalid private key
251240
let invalid_private_key_bytes = [0u8; 32];
252-
assert_eq!(
253-
identity_public_key
254-
.validate_private_key_bytes(&invalid_private_key_bytes, Network::Testnet)
255-
.unwrap(),
256-
false
257-
);
241+
assert!(!identity_public_key
242+
.validate_private_key_bytes(&invalid_private_key_bytes, Network::Testnet)
243+
.unwrap());
258244
}
259245

260246
#[cfg(all(feature = "random-public-keys", feature = "ed25519-dalek"))]
@@ -266,7 +252,7 @@ mod tests {
266252
// Test for EDDSA_25519_HASH160
267253
let key_type = KeyType::EDDSA_25519_HASH160;
268254
let (public_key_data, private_key_data) = key_type
269-
.random_public_and_private_key_data(&mut rng, &platform_version)
255+
.random_public_and_private_key_data(&mut rng, platform_version)
270256
.expect("expected to generate random keys");
271257

272258
let identity_public_key = IdentityPublicKeyV0 {
@@ -281,20 +267,14 @@ mod tests {
281267
};
282268

283269
// Validate that the private key matches the public key
284-
assert_eq!(
285-
identity_public_key
286-
.validate_private_key_bytes(&private_key_data, Network::Testnet)
287-
.unwrap(),
288-
true
289-
);
270+
assert!(identity_public_key
271+
.validate_private_key_bytes(&private_key_data, Network::Testnet)
272+
.unwrap());
290273

291274
// Test with an invalid private key
292275
let invalid_private_key_bytes = [0u8; 32];
293-
assert_eq!(
294-
identity_public_key
295-
.validate_private_key_bytes(&invalid_private_key_bytes, Network::Testnet)
296-
.unwrap(),
297-
false
298-
);
276+
assert!(!identity_public_key
277+
.validate_private_key_bytes(&invalid_private_key_bytes, Network::Testnet)
278+
.unwrap());
299279
}
300280
}

packages/rs-dpp/src/state_transition/state_transitions/identity/identity_credit_transfer_transition/methods/v0/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use crate::{
55
state_transition::StateTransition,
66
ProtocolError,
77
};
8-
use platform_value::Identifier;
98
#[cfg(feature = "state-transition-signing")]
109
use platform_version::version::{FeatureVersion, PlatformVersion};
1110

@@ -15,7 +14,7 @@ pub trait IdentityCreditTransferTransitionMethodsV0 {
1514
#[cfg(feature = "state-transition-signing")]
1615
fn try_from_identity<S: Signer>(
1716
identity: &Identity,
18-
to_identity_with_identifier: Identifier,
17+
to_identity_with_identifier: platform_value::Identifier,
1918
amount: u64,
2019
user_fee_increase: UserFeeIncrease,
2120
signer: S,

0 commit comments

Comments
 (0)