Skip to content

Commit 4f0f9b9

Browse files
authored
feat: coinjoin derivation path support (#63)
* feat: support coinjoin derivation paths * chore: bump version to 0.38.1 * chore: bump up version 39.1
1 parent 9b0d666 commit 4f0f9b9

File tree

3 files changed

+45
-7
lines changed

3 files changed

+45
-7
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ members = ["dash", "hashes", "internals", "fuzz", "rpc-client", "rpc-json", "rpc
33
resolver = "2"
44

55
[workspace.package]
6-
version = "0.39.0"
6+
version = "0.39.1"
77

88
[patch.crates-io.dashcore_hashes]
99
path = "hashes"

dash/src/bip32.rs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,7 @@ use serde;
3636

3737
use crate::base58;
3838
use crate::crypto::key::{self, Keypair, PrivateKey, PublicKey};
39-
use crate::dip9::{
40-
DASH_BIP44_PATH_MAINNET, DASH_BIP44_PATH_TESTNET, IDENTITY_AUTHENTICATION_PATH_MAINNET,
41-
IDENTITY_AUTHENTICATION_PATH_TESTNET, IDENTITY_INVITATION_PATH_MAINNET,
42-
IDENTITY_INVITATION_PATH_TESTNET, IDENTITY_REGISTRATION_PATH_MAINNET,
43-
IDENTITY_REGISTRATION_PATH_TESTNET, IDENTITY_TOPUP_PATH_MAINNET, IDENTITY_TOPUP_PATH_TESTNET,
44-
};
39+
use crate::dip9::{COINJOIN_PATH_MAINNET, COINJOIN_PATH_TESTNET, DASH_BIP44_PATH_MAINNET, DASH_BIP44_PATH_TESTNET, IDENTITY_AUTHENTICATION_PATH_MAINNET, IDENTITY_AUTHENTICATION_PATH_TESTNET, IDENTITY_INVITATION_PATH_MAINNET, IDENTITY_INVITATION_PATH_TESTNET, IDENTITY_REGISTRATION_PATH_MAINNET, IDENTITY_REGISTRATION_PATH_TESTNET, IDENTITY_TOPUP_PATH_MAINNET, IDENTITY_TOPUP_PATH_TESTNET};
4540
use crate::hash_types::XpubIdentifier;
4641
use crate::internal_macros::impl_bytes_newtype;
4742
use crate::io::Write;
@@ -494,6 +489,18 @@ impl DerivationPath {
494489
]);
495490
root_derivation_path
496491
}
492+
pub fn coinjoin_path(
493+
network: Network,
494+
account: u32,
495+
) -> Self {
496+
let mut root_derivation_path: DerivationPath = match network {
497+
Network::Dash => COINJOIN_PATH_MAINNET,
498+
_ => COINJOIN_PATH_TESTNET,
499+
}
500+
.into();
501+
root_derivation_path.0.extend(&[ChildNumber::Hardened { index: account }]);
502+
root_derivation_path
503+
}
497504

498505
/// This might have been used in the past
499506
pub fn identity_registration_path_child_non_hardened(network: Network, index: u32) -> Self {
@@ -2059,6 +2066,15 @@ mod tests {
20592066
assert_eq!(path.to_string(), "m/44'/1'/1'/0/42");
20602067
}
20612068

2069+
#[test]
2070+
fn test_coinjoin_path() {
2071+
let path = DerivationPath::coinjoin_path(Network::Dash, 0);
2072+
assert_eq!(path.to_string(), "m/9'/5'/4'/0'");
2073+
2074+
let path = DerivationPath::coinjoin_path(Network::Testnet, 1);
2075+
assert_eq!(path.to_string(), "m/9'/1'/4'/1'");
2076+
}
2077+
20622078
#[test]
20632079
fn test_identity_registration_path() {
20642080
let path = DerivationPath::identity_registration_path(Network::Dash, 10);

dash/src/dip9.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ pub enum DerivationPathReference {
1515
BlockchainIdentityCreditTopupFunding = 12,
1616
BlockchainIdentityCreditInvitationFunding = 13,
1717
ProviderPlatformNodeKeys = 14,
18+
CoinJoin = 15,
1819
Root = 255,
1920
}
2021

@@ -118,6 +119,7 @@ pub const BIP44_PURPOSE: u32 = 44;
118119
pub const FEATURE_PURPOSE: u32 = 9;
119120
pub const DASH_COIN_TYPE: u32 = 5;
120121
pub const DASH_TESTNET_COIN_TYPE: u32 = 1;
122+
pub const FEATURE_PURPOSE_COINJOIN: u32 = 4;
121123
pub const FEATURE_PURPOSE_IDENTITIES: u32 = 5;
122124
pub const FEATURE_PURPOSE_IDENTITIES_SUBFEATURE_AUTHENTICATION: u32 = 0;
123125
pub const FEATURE_PURPOSE_IDENTITIES_SUBFEATURE_REGISTRATION: u32 = 1;
@@ -149,6 +151,26 @@ pub const DASH_BIP44_PATH_TESTNET: IndexConstPath<2> = IndexConstPath {
149151
reference: DerivationPathReference::BIP44,
150152
path_type: DerivationPathType::CLEAR_FUNDS,
151153
};
154+
// CoinJoin Paths
155+
156+
pub const COINJOIN_PATH_MAINNET: IndexConstPath<3> = IndexConstPath {
157+
indexes: [
158+
ChildNumber::Hardened { index: FEATURE_PURPOSE },
159+
ChildNumber::Hardened { index: DASH_COIN_TYPE },
160+
ChildNumber::Hardened { index: FEATURE_PURPOSE_COINJOIN },
161+
],
162+
reference: DerivationPathReference::CoinJoin,
163+
path_type: DerivationPathType::ANONYMOUS_FUNDS,
164+
};
165+
pub const COINJOIN_PATH_TESTNET: IndexConstPath<3> = IndexConstPath {
166+
indexes: [
167+
ChildNumber::Hardened { index: FEATURE_PURPOSE },
168+
ChildNumber::Hardened { index: DASH_TESTNET_COIN_TYPE },
169+
ChildNumber::Hardened { index: FEATURE_PURPOSE_COINJOIN },
170+
],
171+
reference: DerivationPathReference::CoinJoin,
172+
path_type: DerivationPathType::ANONYMOUS_FUNDS,
173+
};
152174

153175
pub const IDENTITY_REGISTRATION_PATH_MAINNET: IndexConstPath<4> = IndexConstPath {
154176
indexes: [

0 commit comments

Comments
 (0)