diff --git a/Cargo.toml b/Cargo.toml index 986a5b4a2..6ed084c9f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ members = ["dash", "hashes", "internals", "fuzz", "rpc-client", "rpc-json", "rpc resolver = "2" [workspace.package] -version = "0.39.0" +version = "0.39.1" [patch.crates-io.dashcore_hashes] path = "hashes" diff --git a/dash/src/bip32.rs b/dash/src/bip32.rs index d238a8524..c6108a9b4 100644 --- a/dash/src/bip32.rs +++ b/dash/src/bip32.rs @@ -36,12 +36,7 @@ use serde; use crate::base58; use crate::crypto::key::{self, Keypair, PrivateKey, PublicKey}; -use crate::dip9::{ - 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, -}; +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}; use crate::hash_types::XpubIdentifier; use crate::internal_macros::impl_bytes_newtype; use crate::io::Write; @@ -494,6 +489,18 @@ impl DerivationPath { ]); root_derivation_path } + pub fn coinjoin_path( + network: Network, + account: u32, + ) -> Self { + let mut root_derivation_path: DerivationPath = match network { + Network::Dash => COINJOIN_PATH_MAINNET, + _ => COINJOIN_PATH_TESTNET, + } + .into(); + root_derivation_path.0.extend(&[ChildNumber::Hardened { index: account }]); + root_derivation_path + } /// This might have been used in the past pub fn identity_registration_path_child_non_hardened(network: Network, index: u32) -> Self { @@ -2059,6 +2066,15 @@ mod tests { assert_eq!(path.to_string(), "m/44'/1'/1'/0/42"); } + #[test] + fn test_coinjoin_path() { + let path = DerivationPath::coinjoin_path(Network::Dash, 0); + assert_eq!(path.to_string(), "m/9'/5'/4'/0'"); + + let path = DerivationPath::coinjoin_path(Network::Testnet, 1); + assert_eq!(path.to_string(), "m/9'/1'/4'/1'"); + } + #[test] fn test_identity_registration_path() { let path = DerivationPath::identity_registration_path(Network::Dash, 10); diff --git a/dash/src/dip9.rs b/dash/src/dip9.rs index 8842f0196..fd6e07a70 100644 --- a/dash/src/dip9.rs +++ b/dash/src/dip9.rs @@ -15,6 +15,7 @@ pub enum DerivationPathReference { BlockchainIdentityCreditTopupFunding = 12, BlockchainIdentityCreditInvitationFunding = 13, ProviderPlatformNodeKeys = 14, + CoinJoin = 15, Root = 255, } @@ -118,6 +119,7 @@ pub const BIP44_PURPOSE: u32 = 44; pub const FEATURE_PURPOSE: u32 = 9; pub const DASH_COIN_TYPE: u32 = 5; pub const DASH_TESTNET_COIN_TYPE: u32 = 1; +pub const FEATURE_PURPOSE_COINJOIN: u32 = 4; pub const FEATURE_PURPOSE_IDENTITIES: u32 = 5; pub const FEATURE_PURPOSE_IDENTITIES_SUBFEATURE_AUTHENTICATION: u32 = 0; pub const FEATURE_PURPOSE_IDENTITIES_SUBFEATURE_REGISTRATION: u32 = 1; @@ -149,6 +151,26 @@ pub const DASH_BIP44_PATH_TESTNET: IndexConstPath<2> = IndexConstPath { reference: DerivationPathReference::BIP44, path_type: DerivationPathType::CLEAR_FUNDS, }; +// CoinJoin Paths + +pub const COINJOIN_PATH_MAINNET: IndexConstPath<3> = IndexConstPath { + indexes: [ + ChildNumber::Hardened { index: FEATURE_PURPOSE }, + ChildNumber::Hardened { index: DASH_COIN_TYPE }, + ChildNumber::Hardened { index: FEATURE_PURPOSE_COINJOIN }, + ], + reference: DerivationPathReference::CoinJoin, + path_type: DerivationPathType::ANONYMOUS_FUNDS, +}; +pub const COINJOIN_PATH_TESTNET: IndexConstPath<3> = IndexConstPath { + indexes: [ + ChildNumber::Hardened { index: FEATURE_PURPOSE }, + ChildNumber::Hardened { index: DASH_TESTNET_COIN_TYPE }, + ChildNumber::Hardened { index: FEATURE_PURPOSE_COINJOIN }, + ], + reference: DerivationPathReference::CoinJoin, + path_type: DerivationPathType::ANONYMOUS_FUNDS, +}; pub const IDENTITY_REGISTRATION_PATH_MAINNET: IndexConstPath<4> = IndexConstPath { indexes: [