Skip to content

Commit

Permalink
chore: move domain hash names to separate crate
Browse files Browse the repository at this point in the history
  • Loading branch information
Cifko committed Dec 15, 2023
1 parent 93bfd45 commit 6e9c4bf
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 31 deletions.
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion dan_layer/common_types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@ tari_crypto = { workspace = true, features = ["borsh"] }
tari_engine_types = { workspace = true }
tari_bor = { workspace = true, default-features = true }
tari_mmr = { workspace = true }
tari_hash_domains = { git = "https://github.com/tari-project/tari_hash_domains.git" }

libp2p-identity = { workspace = true, features = ["sr25519", "serde", "peerid"] }
libp2p-identity = { workspace = true, features = [
"sr25519",
"serde",
"peerid",
] }

blake2 = { workspace = true }
newtype-ops = { workspace = true }
Expand Down
7 changes: 1 addition & 6 deletions dan_layer/common_types/src/hashing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

use blake2::{digest::consts::U32, Blake2b};
use tari_crypto::{hash_domain, hashing::DomainSeparatedHasher};
use tari_hash_domains::ValidatorNodeBmtHashDomain;
use tari_mmr::{BalancedBinaryMerkleProof, BalancedBinaryMerkleTree, MergedBalancedBinaryMerkleProof};

use crate::hasher::{tari_hasher, TariHasher};
Expand Down Expand Up @@ -55,12 +56,6 @@ fn dan_hasher(label: &'static str) -> TariHasher {
tari_hasher::<TariDanConsensusHashDomain>(label)
}

// From tari_core
hash_domain!(
ValidatorNodeBmtHashDomain,
"com.tari.base_layer.core.validator_node_mmr",
1
);
pub type ValidatorNodeBmtHasherBlake2b = DomainSeparatedHasher<Blake2b<U32>, ValidatorNodeBmtHashDomain>;
pub type ValidatorNodeBalancedMerkleTree = BalancedBinaryMerkleTree<ValidatorNodeBmtHasherBlake2b>;
pub type ValidatorNodeMerkleProof = BalancedBinaryMerkleProof<ValidatorNodeBmtHasherBlake2b>;
Expand Down
1 change: 1 addition & 0 deletions dan_layer/engine_types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ tari_crypto = { workspace = true, features = ["borsh"] }
tari_template_abi = { workspace = true, features = ["std"] }
tari_template_lib = { workspace = true }
tari_utilities = { workspace = true }
tari_hash_domains = { git = "https://github.com/tari-project/tari_hash_domains.git" }

borsh = { workspace = true }
# if we set this version in the workspace it would break other crates
Expand Down
14 changes: 2 additions & 12 deletions dan_layer/engine_types/src/base_layer_hashing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,10 @@ use digest::{
consts::{U32, U64},
Digest,
};
use tari_crypto::{
hash_domain,
hashing::{DomainSeparatedHasher, DomainSeparation},
};
use tari_crypto::hashing::{DomainSeparatedHasher, DomainSeparation};
use tari_hash_domains::{ConfidentialOutputHashDomain, WalletOutputEncryptionKeysDomain};
use tari_template_lib::Hash;

hash_domain!(ConfidentialOutputHashDomain, "com.tari.dan.confidential_output", 1);

hash_domain!(
WalletOutputEncryptionKeysDomain,
"com.tari.base_layer.wallet.output_encryption_keys",
1
);

fn confidential_hasher32(label: &'static str) -> TariBaseLayerHasher32 {
TariBaseLayerHasher32::new_with_label::<ConfidentialOutputHashDomain>(label)
}
Expand Down
7 changes: 2 additions & 5 deletions dan_layer/engine_types/src/hashing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,10 @@ use blake2::{
use digest::Digest;
use serde::Serialize;
use tari_bor::encode_into;
use tari_crypto::{hash_domain, hashing::DomainSeparation};
use tari_crypto::hashing::DomainSeparation;
use tari_hash_domains::TariEngineHashDomain;
use tari_template_lib::Hash;

hash_domain!(TariEngineHashDomain, "com.tari.dan.engine", 0);

pub fn hasher64(label: EngineHashDomainLabel) -> TariHasher64 {
TariHasher64::new_with_label::<TariEngineHashDomain>(label.as_label())
}
Expand All @@ -50,8 +49,6 @@ pub fn template_hasher32() -> TariHasher32 {
hasher32(EngineHashDomainLabel::Template)
}

hash_domain!(ConfidentialOutputHashDomain, "com.tari.dan.confidential_output", 1);

#[derive(Debug, Clone)]
pub struct TariHasher32 {
hasher: Blake2b<U32>,
Expand Down
1 change: 1 addition & 0 deletions dan_layer/wallet/sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ tari_key_manager = { workspace = true }
tari_transaction = { workspace = true }
tari_template_lib = { workspace = true }
tari_utilities = { workspace = true }
tari_hash_domains = { git = "https://github.com/tari-project/tari_hash_domains.git" }

anyhow = { workspace = true }
async-trait = { workspace = true }
Expand Down
8 changes: 1 addition & 7 deletions dan_layer/wallet/sdk/src/confidential/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ use tari_crypto::{
commitment::{ExtensionDegree, HomomorphicCommitmentFactory},
errors::RangeProofError,
extended_range_proof::ExtendedRangeProofService,
hash_domain,
hashing::DomainSeparatedHasher,
keys::SecretKey,
ristretto::bulletproofs_plus::{BulletproofsPlusService, RistrettoExtendedMask, RistrettoExtendedWitness},
tari_utilities::ByteArray,
};
use tari_hash_domains::TransactionSecureNonceKdfDomain;
use tari_template_lib::{
crypto::RistrettoPublicKeyBytes,
models::{Amount, ConfidentialOutputProof, ConfidentialStatement, EncryptedData},
Expand Down Expand Up @@ -119,12 +119,6 @@ pub fn generate_confidential_proof(

fn inner_encrypted_data_kdf_aead(encryption_key: &PrivateKey, commitment: &Commitment) -> EncryptedDataKey32 {
let mut aead_key = EncryptedDataKey32::from(SafeArray::default());
// This has to be the same as the base layer so that burn claims are spendable
hash_domain!(
TransactionSecureNonceKdfDomain,
"com.tari.base_layer.core.transactions.secure_nonce_kdf",
0
);
DomainSeparatedHasher::<Blake2b<U32>, TransactionSecureNonceKdfDomain>::new_with_label("encrypted_value_and_mask")
.chain(encryption_key.as_bytes())
.chain(commitment.as_bytes())
Expand Down

0 comments on commit 6e9c4bf

Please sign in to comment.