mirror of
https://github.com/logos-blockchain/lssa.git
synced 2026-01-07 15:53:14 +00:00
fix: adding core primitives crate
This commit is contained in:
parent
90c8b50689
commit
7f512474dc
16
Cargo.lock
generated
16
Cargo.lock
generated
@ -1202,6 +1202,22 @@ dependencies = [
|
|||||||
"libc",
|
"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]]
|
[[package]]
|
||||||
name = "cpp_demangle"
|
name = "cpp_demangle"
|
||||||
version = "0.4.4"
|
version = "0.4.4"
|
||||||
|
|||||||
@ -18,6 +18,7 @@ members = [
|
|||||||
"rpc_primitives",
|
"rpc_primitives",
|
||||||
"common",
|
"common",
|
||||||
"sc_core",
|
"sc_core",
|
||||||
|
"core_primitives",
|
||||||
]
|
]
|
||||||
|
|
||||||
[workspace.dependencies]
|
[workspace.dependencies]
|
||||||
|
|||||||
20
core_primitives/Cargo.toml
Normal file
20
core_primitives/Cargo.toml
Normal 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"
|
||||||
16
core_primitives/src/commitment.rs
Normal file
16
core_primitives/src/commitment.rs
Normal 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,
|
||||||
|
}
|
||||||
5
core_primitives/src/lib.rs
Normal file
5
core_primitives/src/lib.rs
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
pub mod commitment;
|
||||||
|
pub mod merkle_tree_public;
|
||||||
|
pub mod nullifier;
|
||||||
|
pub mod transaction;
|
||||||
|
pub mod utxo;
|
||||||
2
core_primitives/src/merkle_tree_public.rs
Normal file
2
core_primitives/src/merkle_tree_public.rs
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
pub type TreeHashType = [u8; 32];
|
||||||
|
pub type CommitmentHashType = Vec<u8>;
|
||||||
18
core_primitives/src/nullifier.rs
Normal file
18
core_primitives/src/nullifier.rs
Normal 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,
|
||||||
|
}
|
||||||
67
core_primitives/src/transaction.rs
Normal file
67
core_primitives/src/transaction.rs
Normal 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>,
|
||||||
|
}
|
||||||
29
core_primitives/src/utxo.rs
Normal file
29
core_primitives/src/utxo.rs
Normal 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,
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user