Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: remove serde-byte-array #909

Merged
merged 1 commit into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 3 additions & 12 deletions Cargo.lock

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

11 changes: 5 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ resolver = "2"
# specifying them in a single place and having them applied to all crates

# internal dependencies among workspace crates
libp2p-messaging = { path = "networking/libp2p-messaging"}
libp2p-peersync = { path = "networking/libp2p-peersync"}
libp2p-messaging = { path = "networking/libp2p-messaging" }
libp2p-peersync = { path = "networking/libp2p-peersync" }
libp2p-substream = { path = "networking/libp2p-substream" }
proto_builder = { path = "networking/proto_builder" }
sqlite_message_logger = { path = "networking/sqlite_message_logger" }
Expand Down Expand Up @@ -87,10 +87,10 @@ tari_rpc_framework = { path = "networking/rpc_framework" }
tari_rpc_macros = { path = "networking/rpc_macros" }
tari_state_store_sqlite = { path = "dan_layer/state_store_sqlite" }
tari_swarm = { path = "networking/swarm" }
tari_template_abi = { version="0.3.0", path = "dan_layer/template_abi" }
tari_template_abi = { version = "0.3.0", path = "dan_layer/template_abi" }
tari_template_builtin = { path = "dan_layer/template_builtin" }
tari_template_lib = { path = "dan_layer/template_lib" }
tari_template_macros = { version="0.3.0", path = "dan_layer/template_macros" }
tari_template_macros = { version = "0.3.0", path = "dan_layer/template_macros" }
tari_template_test_tooling = { path = "dan_layer/template_test_tooling" }
tari_transaction = { path = "dan_layer/transaction" }
tari_transaction_manifest = { path = "dan_layer/transaction_manifest" }
Expand Down Expand Up @@ -198,7 +198,6 @@ semver = "1.0"
serde = { version = "1.0", default-features = false }
serde_json = "1.0"
serde_with = "2.3"
serde-byte-array = "0.1.2"
sha2 = "0.10.8"
smallvec = "2.0.0-alpha.1"
std-semaphore = "0.1.0"
Expand All @@ -211,7 +210,7 @@ tokio-stream = "0.1.7"
tokio-util = "0.7.10"
tonic = "0.6.2"
tower = "0.4"
tower-http = { version = "0.3.5", default-features = false}
tower-http = { version = "0.3.5", default-features = false }
tower-layer = "0.3"
tracing = "0.1.40"
url = "2.4.1"
Expand Down
13 changes: 5 additions & 8 deletions dan_layer/template_lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ tari_template_macros = { workspace = true, optional = true }
tari_bor = { workspace = true, default-features = false }

newtype-ops = { workspace = true }
serde = { workspace = true, default-features = false, features = ["derive", "alloc"] }
serde-byte-array = { workspace = true }
serde = { workspace = true, default-features = false, features = [
"derive",
"alloc",
] }
serde_with = { workspace = true }

[dev-dependencies]
serde_json = { workspace = true }
Expand All @@ -23,9 +26,3 @@ serde_json = { workspace = true }
default = ["macro", "std"]
macro = ["tari_template_macros"]
std = ["serde/std", "tari_bor/std"]

[package.metadata.cargo-machete]
ignored = [
# Used but not detectable by machete
"serde-byte-array",
]
4 changes: 3 additions & 1 deletion dan_layer/template_lib/src/crypto/balance_proof.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
// Copyright 2023 The Tari Project
// SPDX-License-Identifier: BSD-3-Clause
use serde::{Deserialize, Serialize};
use serde_with::{serde_as, Bytes};

use crate::crypto::InvalidByteLengthError;

/// The signature of a balance proof, used to validate the authorship of confidential transfers
#[serde_as]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(transparent)]
pub struct BalanceProofSignature(#[serde(with = "serde_byte_array")] [u8; BalanceProofSignature::length()]);
pub struct BalanceProofSignature(#[serde_as(as = "Bytes")] [u8; BalanceProofSignature::length()]);

impl BalanceProofSignature {
pub const fn length() -> usize {
Expand Down
4 changes: 3 additions & 1 deletion dan_layer/template_lib/src/crypto/commitment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
// SPDX-License-Identifier: BSD-3-Clause

use serde::{Deserialize, Serialize};
use serde_with::{serde_as, Bytes};
use tari_template_abi::rust::fmt::{Display, Formatter};

use crate::{crypto::InvalidByteLengthError, Hash};

/// A Pederson Commitment byte contents
#[serde_as]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Ord, PartialOrd, Hash, Default, Serialize, Deserialize)]
#[serde(transparent)]
pub struct PedersonCommitmentBytes(#[serde(with = "serde_byte_array")] [u8; PedersonCommitmentBytes::length()]);
pub struct PedersonCommitmentBytes(#[serde_as(as = "Bytes")] [u8; PedersonCommitmentBytes::length()]);

impl PedersonCommitmentBytes {
pub const fn length() -> usize {
Expand Down
4 changes: 3 additions & 1 deletion dan_layer/template_lib/src/crypto/ristretto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
// SPDX-License-Identifier: BSD-3-Clause

use serde::{Deserialize, Serialize};
use serde_with::{serde_as, Bytes};
use tari_template_abi::rust::fmt::{Display, Formatter};

use crate::{crypto::InvalidByteLengthError, models::NonFungibleAddress, Hash};

/// A Ristretto public key byte contents
#[serde_as]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default, Serialize, Deserialize)]
#[serde(transparent)]
pub struct RistrettoPublicKeyBytes(#[serde(with = "serde_byte_array")] [u8; RistrettoPublicKeyBytes::length()]);
pub struct RistrettoPublicKeyBytes(#[serde_as(as = "Bytes")] [u8; RistrettoPublicKeyBytes::length()]);

impl RistrettoPublicKeyBytes {
pub const fn length() -> usize {
Expand Down
4 changes: 3 additions & 1 deletion dan_layer/template_lib/src/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ use std::{
};

use serde::{Deserialize, Serialize};
use serde_with::{serde_as, Bytes};

/// Representation of a 32-byte hash value
#[serde_as]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Ord, PartialOrd, Hash, Default, Serialize, Deserialize)]
#[serde(transparent)]
pub struct Hash([u8; 32]);
pub struct Hash(#[serde_as(as = "Bytes")] [u8; 32]);

impl Hash {
pub const fn from_array(bytes: [u8; 32]) -> Self {
Expand Down
7 changes: 5 additions & 2 deletions dan_layer/template_lib/src/models/confidential_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: BSD-3-Clause

use serde::{Deserialize, Serialize};
use serde_with::{serde_as, Bytes};

use crate::{
crypto::{BalanceProofSignature, PedersonCommitmentBytes, RistrettoPublicKeyBytes},
Expand All @@ -21,9 +22,10 @@ pub struct ConfidentialOutputProof {
}

/// A zero-knowledge proof that a confidential resource amount is valid
#[serde_as]
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct ConfidentialStatement {
#[serde(with = "serde_byte_array")]
#[serde_as(as = "Bytes")]
pub commitment: [u8; 32],
/// Public nonce (R) that was used to generate the commitment mask
// #[cfg_attr(feature = "serde", serde(with = "hex::serde"))]
Expand All @@ -47,9 +49,10 @@ pub struct ConfidentialWithdrawProof {

/// Used by the receiver to determine the value component of the commitment, in both confidential transfers and Minotari
/// burns
#[serde_as]
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(transparent)]
pub struct EncryptedData(#[serde(with = "serde_byte_array")] pub [u8; EncryptedData::size()]);
pub struct EncryptedData(#[serde_as(as = "Bytes")] pub [u8; EncryptedData::size()]);

impl EncryptedData {
pub const fn size() -> usize {
Expand Down
4 changes: 3 additions & 1 deletion dan_layer/template_lib/src/models/non_fungible.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: BSD-3-Clause

use serde::{de::DeserializeOwned, Deserialize, Serialize};
use serde_with::{serde_as, Bytes};
use tari_bor::BorTag;
use tari_template_abi::{
call_engine,
Expand All @@ -22,9 +23,10 @@ use crate::{
const DELIM: char = ':';

/// The unique identification of a non-fungible token inside it's parent resource
#[serde_as]
#[derive(Debug, Clone, Ord, PartialOrd, PartialEq, Eq, Serialize, Deserialize, Hash)]
pub enum NonFungibleId {
U256(#[serde(with = "serde_byte_array")] [u8; 32]),
U256(#[serde_as(as = "Bytes")] [u8; 32]),
String(String),
Uint32(u32),
Uint64(u64),
Expand Down
Loading