Skip to content

Commit 5acc734

Browse files
feat: identity derivation path changes
1 parent db9ad0d commit 5acc734

File tree

5 files changed

+48
-41
lines changed

5 files changed

+48
-41
lines changed

dash/src/bip32.rs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,8 @@ impl DerivationPath {
398398
root_derivation_path
399399
}
400400

401-
pub fn identity_registration_path(network: Network, index: u32) -> Self {
401+
/// This might have been used in the past
402+
pub fn identity_registration_path_child_non_hardened(network: Network, index: u32) -> Self {
402403
let mut root_derivation_path: DerivationPath = match network {
403404
Network::Dash => IDENTITY_REGISTRATION_PATH_MAINNET,
404405
_ => IDENTITY_REGISTRATION_PATH_TESTNET,
@@ -408,13 +409,26 @@ impl DerivationPath {
408409
root_derivation_path
409410
}
410411

411-
pub fn identity_top_up_path(network: Network, index: u32) -> Self {
412+
pub fn identity_registration_path(network: Network, index: u32) -> Self {
413+
let mut root_derivation_path: DerivationPath = match network {
414+
Network::Dash => IDENTITY_REGISTRATION_PATH_MAINNET,
415+
_ => IDENTITY_REGISTRATION_PATH_TESTNET,
416+
}
417+
.into();
418+
root_derivation_path.0.extend(&[ChildNumber::Hardened { index }]);
419+
root_derivation_path
420+
}
421+
422+
pub fn identity_top_up_path(network: Network, identity_index: u32, top_up_index: u32) -> Self {
412423
let mut root_derivation_path: DerivationPath = match network {
413424
Network::Dash => IDENTITY_TOPUP_PATH_MAINNET,
414425
_ => IDENTITY_TOPUP_PATH_TESTNET,
415426
}
416427
.into();
417-
root_derivation_path.0.extend(&[ChildNumber::Normal { index }]);
428+
root_derivation_path.0.extend(&[
429+
ChildNumber::Hardened { index: identity_index },
430+
ChildNumber::Normal { index: top_up_index },
431+
]);
418432
root_derivation_path
419433
}
420434

@@ -424,7 +438,7 @@ impl DerivationPath {
424438
_ => IDENTITY_INVITATION_PATH_TESTNET,
425439
}
426440
.into();
427-
root_derivation_path.0.extend(&[ChildNumber::Normal { index }]);
441+
root_derivation_path.0.extend(&[ChildNumber::Hardened { index }]);
428442
root_derivation_path
429443
}
430444

@@ -1820,13 +1834,13 @@ mod tests {
18201834
#[test]
18211835
fn test_identity_registration_path() {
18221836
let path = DerivationPath::identity_registration_path(Network::Dash, 10);
1823-
assert_eq!(path.to_string(), "m/9'/5'/5'/1'/10");
1837+
assert_eq!(path.to_string(), "m/9'/5'/5'/1'/10'");
18241838
}
18251839

18261840
#[test]
18271841
fn test_identity_top_up_path() {
1828-
let path = DerivationPath::identity_top_up_path(Network::Testnet, 2);
1829-
assert_eq!(path.to_string(), "m/9'/1'/5'/2'/2");
1842+
let path = DerivationPath::identity_top_up_path(Network::Testnet, 2, 3);
1843+
assert_eq!(path.to_string(), "m/9'/1'/5'/2'/2'/3");
18301844
}
18311845

18321846
#[test]

dash/src/blockdata/block.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,6 @@ mod tests {
468468

469469
#[test]
470470
fn block_test_2() {
471-
472471
let some_block = hex!(
473472
"000000200ec684405b58b3a0f0144c9a92c7d4296587ba6fc71041fff2130a038a00000078e259b490cfc8a8e50e1933afde3f777a47bdac8b61d504a51b68dede2ac181cd0822679008011e2e0506000103000500010000000000000000000000000000000000000000000000000000000000000000ffffffff06031e42110101ffffffff037a681d04000000001976a914c69a0bda7daaae481be8def95e5f347a1d00a4b488ac8815a10400000000016ae523b707000000001976a91464f2b2b84f62d68a2cd7f7f5fb2b5aa75ef716d788ac00000000af03001e421100032459005e51c0c2180b5a06001eacee43e1ab9a169dc0c9fb8ca40506258fed68c5aa969c10a3015bde2cfbe1700c795f97a4fa3946e9de4decc14d3a2117be00b695cd60fa9339a8318b65dab7a8a45655ffc6daf0ff1b0b19958903460613f92ac911f3b80bf71bfaeff3968aff87dd0750233a73145f913a3a2a9b1ddaca1ef8f14738870767a80d539ad639837dff1140f78b8f4d65eb4216b7128b736a2453afd99ce4040000"
474473
);

dash/src/blockdata/transaction/special_transaction/coinbase.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818
//! It is defined in DIP4 [dip-0004](https://github.com/dashpay/dips/blob/master/dip-0004.md).
1919
//!
2020
21+
use crate::bls_sig_utils::BLSSignature;
22+
use crate::consensus::encode::{compact_size_len, read_compact_size, write_compact_size};
2123
use crate::consensus::{Decodable, Encodable, encode};
2224
use crate::hash_types::{MerkleRootMasternodeList, MerkleRootQuorums};
2325
use crate::io::{Error, ErrorKind};
2426
use crate::{VarInt, io};
25-
use crate::bls_sig_utils::BLSSignature;
26-
use crate::consensus::encode::{compact_size_len, read_compact_size, write_compact_size};
2727

2828
/// A Coinbase payload. This is contained as the payload of a coinbase special transaction.
2929
/// The Coinbase payload is described in DIP4.
@@ -95,9 +95,7 @@ impl Decodable for CoinbasePayload {
9595
let height = u32::consensus_decode(r)?;
9696
let merkle_root_masternode_list = MerkleRootMasternodeList::consensus_decode(r)?;
9797
let merkle_root_quorums = MerkleRootQuorums::consensus_decode(r)?;
98-
let best_cl_height = if version >= 3 {
99-
Some(read_compact_size(r)?)
100-
} else { None };
98+
let best_cl_height = if version >= 3 { Some(read_compact_size(r)?) } else { None };
10199
let best_cl_signature =
102100
if version >= 3 { Some(BLSSignature::consensus_decode(r)?) } else { None };
103101
let asset_locked_amount = if version >= 3 { Some(u64::consensus_decode(r)?) } else { None };
@@ -116,6 +114,7 @@ impl Decodable for CoinbasePayload {
116114
#[cfg(test)]
117115
mod tests {
118116
use hashes::Hash;
117+
119118
use crate::bls_sig_utils::BLSSignature;
120119
use crate::consensus::Encodable;
121120
use crate::hash_types::{MerkleRootMasternodeList, MerkleRootQuorums};

dash/src/blockdata/transaction/special_transaction/quorum_commitment.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,16 @@
1818
//!
1919
2020
use std::io::{Read, Write};
21+
2122
use crate::bls_sig_utils::{BLSPublicKey, BLSSignature};
23+
use crate::consensus::encode::{
24+
compact_size_len, fixed_bitset_len, read_compact_size, read_fixed_bitset, write_compact_size,
25+
write_fixed_bitset,
26+
};
2227
use crate::consensus::{Decodable, Encodable, encode};
2328
use crate::hash_types::{QuorumHash, QuorumVVecHash};
2429
use crate::prelude::*;
2530
use crate::{VarInt, io};
26-
use crate::consensus::encode::{compact_size_len, fixed_bitset_len, read_compact_size, read_fixed_bitset, write_compact_size, write_fixed_bitset};
2731

2832
/// A Quorum Finalization Commitment. It is described in the finalization section of DIP6:
2933
/// [dip-0006.md#6-finalization-phase](https://github.com/dashpay/dips/blob/master/dip-0006.md#6-finalization-phase)
@@ -73,7 +77,8 @@ impl Encodable for QuorumFinalizationCommitment {
7377
len += write_compact_size(w, self.signers.len() as u32)?;
7478
len += write_fixed_bitset(w, self.signers.as_slice(), self.signers.iter().len())?;
7579
len += write_compact_size(w, self.valid_members.len() as u32)?;
76-
len += write_fixed_bitset(w, self.valid_members.as_slice(), self.valid_members.iter().len())?;
80+
len +=
81+
write_fixed_bitset(w, self.valid_members.as_slice(), self.valid_members.iter().len())?;
7782
len += self.quorum_public_key.consensus_encode(w)?;
7883
len += self.quorum_vvec_hash.consensus_encode(w)?;
7984
len += self.quorum_sig.consensus_encode(w)?;
@@ -87,7 +92,8 @@ impl Decodable for QuorumFinalizationCommitment {
8792
let version = u16::consensus_decode(r)?;
8893
let llmq_type = u8::consensus_decode(r)?;
8994
let quorum_hash = QuorumHash::consensus_decode(r)?;
90-
let quorum_index = if version == 2 || version == 4 { Some(i16::consensus_decode(r)?) } else { None };
95+
let quorum_index =
96+
if version == 2 || version == 4 { Some(i16::consensus_decode(r)?) } else { None };
9197
let signers_count = read_compact_size(r)?;
9298
let signers = read_fixed_bitset(r, signers_count as usize)?;
9399
let valid_members_count = read_compact_size(r)?;
@@ -156,7 +162,9 @@ mod tests {
156162
use crate::bls_sig_utils::{BLSPublicKey, BLSSignature};
157163
use crate::consensus::Encodable;
158164
use crate::hash_types::{QuorumHash, QuorumVVecHash};
159-
use crate::transaction::special_transaction::quorum_commitment::{QuorumCommitmentPayload, QuorumFinalizationCommitment};
165+
use crate::transaction::special_transaction::quorum_commitment::{
166+
QuorumCommitmentPayload, QuorumFinalizationCommitment,
167+
};
160168

161169
#[test]
162170
fn size() {

dash/src/consensus/encode.rs

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
use core::convert::From;
3434
use core::{fmt, mem, u32};
3535
use std::io::Write;
36+
3637
#[cfg(feature = "core-block-hash-use-x11")]
3738
use hashes::hash_x11;
3839
use hashes::{Hash, hash160, sha256, sha256d};
@@ -935,10 +936,7 @@ pub fn read_compact_size<R: Read + ?Sized>(r: &mut R) -> io::Result<u32> {
935936
}
936937
0xFF => {
937938
// Value is too large to fit in u32
938-
Err(io::Error::new(
939-
io::ErrorKind::InvalidData,
940-
"CompactSize value exceeds u32::MAX",
941-
))
939+
Err(io::Error::new(io::ErrorKind::InvalidData, "CompactSize value exceeds u32::MAX"))
942940
}
943941
value => Ok(value as u32),
944942
}
@@ -967,11 +965,9 @@ pub fn compact_size_len(value: u32) -> usize {
967965
let mut size: usize = 0;
968966
if value < 253 {
969967
size += 1;
970-
}
971-
else if value < 65536 {
968+
} else if value < 65536 {
972969
size += 3;
973-
}
974-
else {
970+
} else {
975971
size += 5;
976972
}
977973
size
@@ -1004,7 +1000,11 @@ pub fn read_fixed_bitset<R: Read + ?Sized>(r: &mut R, size: usize) -> std::io::R
10041000
Ok(bits)
10051001
}
10061002

1007-
pub fn write_fixed_bitset<W: Write + ?Sized>(w: &mut W, bits: &[bool], size: usize) -> io::Result<usize> {
1003+
pub fn write_fixed_bitset<W: Write + ?Sized>(
1004+
w: &mut W,
1005+
bits: &[bool],
1006+
size: usize,
1007+
) -> io::Result<usize> {
10081008
if bits.len() < size {
10091009
return Err(io::Error::new(
10101010
io::ErrorKind::InvalidInput,
@@ -1452,21 +1452,8 @@ mod tests {
14521452

14531453
#[test]
14541454
fn test_compact_size_round_trip() {
1455-
let test_values = vec![
1456-
0u32,
1457-
1,
1458-
252,
1459-
253,
1460-
254,
1461-
255,
1462-
300,
1463-
5000,
1464-
65535,
1465-
65536,
1466-
70000,
1467-
1_000_000,
1468-
u32::MAX,
1469-
];
1455+
let test_values =
1456+
vec![0u32, 1, 252, 253, 254, 255, 300, 5000, 65535, 65536, 70000, 1_000_000, u32::MAX];
14701457

14711458
for &value in &test_values {
14721459
let mut buffer = Vec::new();

0 commit comments

Comments
 (0)