Skip to content

Commit

Permalink
Make tari_hashing no-std and move domain hashes
Browse files Browse the repository at this point in the history
  • Loading branch information
brianp committed May 17, 2024
1 parent dcf3451 commit d5c9a62
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 25 deletions.
4 changes: 3 additions & 1 deletion applications/minotari_ledger_wallet/wallet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@ license = "BSD-3-Clause"
edition = "2021"

[dependencies]
tari_crypto = { version = "0.20.1", default-features = false, features = ["borsh"]}
tari_hashing = { path = "../../../hashing", version = "1.0.0-pre.13" }

blake2 = { version = "0.10", default-features = false }
borsh = { version = "1.2", default-features = false }
critical-section = { version = "1.1.1" }
digest = { version = "0.10", default-features = false }
embedded-alloc = "0.5.0"
include_gif = "1.0.1"
ledger_device_sdk = "1.7.1"
tari_crypto = { version = "0.20.1", default-features = false, features = ["borsh"]}
zeroize = { version = "1" , default-features = false }

# once_cell defined here just to lock the version. Other dependencies may try to go to 1.19 which is incompatabile with
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ use tari_crypto::{
RistrettoSecretKey,
},
};
use tari_hashing::TransactionHashDomain;

use crate::{
alloc::string::ToString,
hashing::{DomainSeparatedConsensusHasher, TransactionHashDomain},
hashing::DomainSeparatedConsensusHasher,
utils::{derive_from_bip32_key, get_key_from_canonical_bytes},
AppSW,
KeyType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ use tari_crypto::{
RistrettoSecretKey,
},
};
use tari_hashing::TransactionHashDomain;
use zeroize::Zeroizing;

use crate::{
alloc::string::ToString,
hashing::{DomainSeparatedConsensusHasher, TransactionHashDomain},
hashing::DomainSeparatedConsensusHasher,
utils::{alpha_hasher, derive_from_bip32_key, get_key_from_canonical_bytes},
AppSW,
KeyType,
Expand Down
10 changes: 1 addition & 9 deletions applications/minotari_ledger_wallet/wallet/src/hashing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,7 @@ use core::marker::PhantomData;

use borsh::{io, io::Write, BorshSerialize};
use digest::Digest;
use tari_crypto::{hash_domain, hashing::DomainSeparation};

hash_domain!(LedgerHashDomain, "com.tari.minotari_ledger_wallet", 0);
hash_domain!(
KeyManagerTransactionsHashDomain,
"com.tari.base_layer.core.transactions.key_manager",
1
);
hash_domain!(TransactionHashDomain, "com.tari.base_layer.core.transactions", 0);
use tari_crypto::hashing::DomainSeparation;

pub struct DomainSeparatedConsensusHasher<M, D> {
hasher: DomainSeparatedBorshHasher<M, D>,
Expand Down
2 changes: 1 addition & 1 deletion applications/minotari_ledger_wallet/wallet/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ use tari_crypto::{
ristretto::RistrettoSecretKey,
tari_utilities::ByteArray,
};
use tari_hashing::{KeyManagerTransactionsHashDomain, LedgerHashDomain};
use zeroize::Zeroizing;

use crate::{
alloc::string::{String, ToString},
hashing::{KeyManagerTransactionsHashDomain, LedgerHashDomain},
AppSW,
KeyType,
BIP32_COIN_TYPE,
Expand Down
8 changes: 1 addition & 7 deletions base_layer/core/src/transactions/key_manager/inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ use tari_comms::types::CommsDHKE;
use tari_crypto::{
commitment::{ExtensionDegree, HomomorphicCommitmentFactory},
extended_range_proof::ExtendedRangeProofService,
hash_domain,
hashing::{DomainSeparatedHash, DomainSeparatedHasher},
keys::{PublicKey as PublicKeyTrait, SecretKey},
range_proof::RangeProofService as RPService,
Expand All @@ -48,6 +47,7 @@ use tari_crypto::{
RistrettoComSig,
},
};
use tari_hashing::KeyManagerTransactionsHashDomain;
#[cfg(feature = "ledger")]
use tari_key_manager::error::KeyManagerError;
use tari_key_manager::{
Expand Down Expand Up @@ -92,12 +92,6 @@ use crate::{
},
};

hash_domain!(
KeyManagerTransactionsHashDomain,
"com.tari.base_layer.core.transactions.key_manager",
1
);

pub struct TransactionKeyManagerInner<TBackend> {
key_managers: HashMap<String, RwLock<KeyManager<PublicKey, KeyDigest>>>,
db: KeyManagerDatabase<TBackend, PublicKey>,
Expand Down
6 changes: 3 additions & 3 deletions hashing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ license = "BSD-3-Clause"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
tari_crypto = { version = "0.20.1" }
digest = "0.10"
borsh = "1.2"
tari_crypto = { version = "0.20.1", default-features = false, features = ["borsh"]}
borsh = { version = "1.2", default-features = false }
digest = { version = "0.10", default-features = false }

[dev-dependencies]
blake2 = "0.10"
7 changes: 5 additions & 2 deletions hashing/src/borsh_hasher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

use std::{io, io::Write, marker::PhantomData};
use core::marker::PhantomData;

use borsh::BorshSerialize;
use borsh::{io, io::Write, BorshSerialize};
use digest::Digest;
use tari_crypto::hashing::DomainSeparation;

Expand Down Expand Up @@ -79,6 +79,9 @@ impl<D: Digest> Write for WriteHashWrapper<D> {

#[cfg(test)]
mod tests {
extern crate alloc;
use alloc::vec::Vec;

use blake2::Blake2b;
use digest::consts::U32;
use tari_crypto::hash_domain;
Expand Down
8 changes: 8 additions & 0 deletions hashing/src/domains.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,11 @@ hash_domain!(
// Hash domain for all transaction-related hashes, including the script signature challenge, transaction hash and kernel
// signature challenge
hash_domain!(TransactionHashDomain, "com.tari.base_layer.core.transactions", 0);

hash_domain!(LedgerHashDomain, "com.tari.minotari_ledger_wallet", 0);

hash_domain!(
KeyManagerTransactionsHashDomain,
"com.tari.base_layer.core.transactions.key_manager",
1
);
3 changes: 3 additions & 0 deletions hashing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

// This library is no_std because it's used everywhere including ledger devices.
#![no_std]

mod domains;
pub use domains::*;

Expand Down

0 comments on commit d5c9a62

Please sign in to comment.