fix: adding core primitives crate

This commit is contained in:
Oleksandr Pravdyvyi 2025-03-17 13:18:44 +02:00
parent 90c8b50689
commit 7f512474dc
9 changed files with 174 additions and 0 deletions

16
Cargo.lock generated
View File

@ -1202,6 +1202,22 @@ dependencies = [
"libc",
]
[[package]]
name = "core_primitives"
version = "0.1.0"
dependencies = [
"anyhow",
"elliptic-curve",
"env_logger",
"log",
"monotree",
"sequencer_core",
"serde",
"serde_json",
"sha2 0.10.8",
"storage",
]
[[package]]
name = "cpp_demangle"
version = "0.4.4"

View File

@ -18,6 +18,7 @@ members = [
"rpc_primitives",
"common",
"sc_core",
"core_primitives",
]
[workspace.dependencies]

View File

@ -0,0 +1,20 @@
[package]
name = "core_primitives"
version = "0.1.0"
edition = "2021"
[dependencies]
anyhow.workspace = true
serde_json.workspace = true
env_logger.workspace = true
log.workspace = true
serde.workspace = true
sha2.workspace = true
elliptic-curve.workspace = true
monotree.workspace = true
[dependencies.storage]
path = "../storage"
[dependencies.sequencer_core]
path = "../sequencer_core"

View File

@ -0,0 +1,16 @@
use crate::merkle_tree_public::CommitmentHashType;
use monotree::database::MemoryDB;
use monotree::hasher::Blake3;
use monotree::{Hasher, Monotree, Proof};
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize, Clone, Default, PartialEq, Eq)]
pub struct Commitment {
pub commitment_hash: CommitmentHashType,
}
pub struct CommitmentsSparseMerkleTree {
pub curr_root: Option<CommitmentHashType>,
pub tree: Monotree<MemoryDB, Blake3>,
pub hasher: Blake3,
}

View File

@ -0,0 +1,5 @@
pub mod commitment;
pub mod merkle_tree_public;
pub mod nullifier;
pub mod transaction;
pub mod utxo;

View File

@ -0,0 +1,2 @@
pub type TreeHashType = [u8; 32];
pub type CommitmentHashType = Vec<u8>;

View File

@ -0,0 +1,18 @@
use crate::merkle_tree_public::TreeHashType;
use monotree::database::MemoryDB;
use monotree::hasher::Blake3;
use monotree::{Hasher, Monotree, Proof};
use serde::{Deserialize, Serialize};
//ToDo: Update Nullifier model, when it is clear
#[derive(Debug, Serialize, Deserialize, Clone, Default, PartialEq, Eq)]
///General nullifier object
pub struct UTXONullifier {
pub utxo_hash: TreeHashType,
}
pub struct NullifierSparseMerkleTree {
pub curr_root: Option<TreeHashType>,
pub tree: Monotree<MemoryDB, Blake3>,
pub hasher: Blake3,
}

View File

@ -0,0 +1,67 @@
use log::info;
use serde::{Deserialize, Serialize};
use sha2::{digest::FixedOutput, Digest};
use crate::merkle_tree_public::TreeHashType;
use elliptic_curve::{
consts::{B0, B1},
generic_array::GenericArray,
};
use sha2::digest::typenum::{UInt, UTerm};
pub type CipherText = Vec<u8>;
pub type Nonce = GenericArray<u8, UInt<UInt<UInt<UInt<UTerm, B1>, B1>, B0>, B0>>;
#[derive(Debug, Serialize, Deserialize, Clone, Copy)]
pub enum TxKind {
Public,
Private,
Shielded,
Deshielded,
}
#[derive(Debug, Serialize, Deserialize, Clone)]
///General transaction object
pub struct Transaction {
pub hash: TreeHashType,
pub tx_kind: TxKind,
///Tx input data (public part)
pub execution_input: Vec<u8>,
///Tx output data (public_part)
pub execution_output: Vec<u8>,
///Tx input utxo commitments
pub utxo_commitments_spent_hashes: Vec<TreeHashType>,
///Tx output utxo commitments
pub utxo_commitments_created_hashes: Vec<TreeHashType>,
///Tx output nullifiers
pub nullifier_created_hashes: Vec<TreeHashType>,
///Execution proof (private part)
pub execution_proof_private: String,
///Encoded blobs of data
pub encoded_data: Vec<(CipherText, Vec<u8>)>,
///Transaction senders ephemeral pub key
pub ephemeral_pub_key: Vec<u8>,
}
#[derive(Debug, Serialize, Deserialize, Clone)]
///General transaction object
pub struct TransactionPayload {
pub tx_kind: TxKind,
///Tx input data (public part)
pub execution_input: Vec<u8>,
///Tx output data (public_part)
pub execution_output: Vec<u8>,
///Tx input utxo commitments
pub utxo_commitments_spent_hashes: Vec<TreeHashType>,
///Tx output utxo commitments
pub utxo_commitments_created_hashes: Vec<TreeHashType>,
///Tx output nullifiers
pub nullifier_created_hashes: Vec<TreeHashType>,
///Execution proof (private part)
pub execution_proof_private: String,
///Encoded blobs of data
pub encoded_data: Vec<(CipherText, Vec<u8>)>,
///Transaction senders ephemeral pub key
pub ephemeral_pub_key: Vec<u8>,
}

View File

@ -0,0 +1,29 @@
use anyhow::Result;
use log::info;
use serde::{Deserialize, Serialize};
use sha2::{digest::FixedOutput, Digest};
use storage::{merkle_tree_public::TreeHashType, nullifier::UTXONullifier, AccountId};
///Raw asset data
pub type Asset = Vec<u8>;
#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
///Container for raw utxo payload
pub struct UTXO {
pub hash: TreeHashType,
pub owner: AccountId,
pub nullifier: Option<UTXONullifier>,
pub asset: Asset,
// TODO: change to u256
pub amount: u128,
pub privacy_flag: bool,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct UTXOPayload {
pub owner: AccountId,
pub asset: Asset,
// TODO: change to u256
pub amount: u128,
pub privacy_flag: bool,
}