init
This commit is contained in:
parent
c09b06a5a5
commit
984fdb99db
14
.gitignore
vendored
Normal file
14
.gitignore
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
# Generated by Cargo
|
||||
# will have compiled files and executables
|
||||
debug/
|
||||
target/
|
||||
|
||||
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
|
||||
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
|
||||
Cargo.lock
|
||||
|
||||
# These are backup files generated by rustfmt
|
||||
**/*.rs.bk
|
||||
|
||||
# MSVC Windows builds of rustc generate these, which store debugging information
|
||||
*.pdb
|
23
Cargo.toml
Normal file
23
Cargo.toml
Normal file
@ -0,0 +1,23 @@
|
||||
[package]
|
||||
name = "sdk_common"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib", "rlib"]
|
||||
|
||||
[dependencies]
|
||||
wasm-bindgen = "0.2.90"
|
||||
serde = { version = "1.0.193", features = ["derive"] }
|
||||
serde_json = "1.0.108"
|
||||
# sp_backend = { git = "https://github.com/Sosthene00/sp-backend.git", branch = "master" }
|
||||
# silentpayments = { git = "https://github.com/Sosthene00/rust-silentpayments", branch = "utils" }
|
||||
rand = "0.8.5"
|
||||
hex = "0.4.3"
|
||||
uuid = { version = "1.6.1", features = ["serde", "v4"] }
|
||||
sha2 = "0.10.8"
|
||||
chrono = "0.4.31"
|
||||
aes-gcm = "0.10.3"
|
||||
aes = "0.8.3"
|
||||
base64 = "0.21.7"
|
||||
rocket = { version = "0.5.0", features = ["json"] }
|
0
migrations.toml
Normal file
0
migrations.toml
Normal file
3
src/lib.rs
Normal file
3
src/lib.rs
Normal file
@ -0,0 +1,3 @@
|
||||
pub mod models;
|
||||
pub mod wallet;
|
||||
pub mod workflows;
|
5
src/main.rs
Normal file
5
src/main.rs
Normal file
@ -0,0 +1,5 @@
|
||||
use sdk_common::models;
|
||||
use sdk_common::wallet;
|
||||
use sdk_common::workflows;
|
||||
|
||||
fn main() {}
|
14
src/models/commitment_method.rs
Normal file
14
src/models/commitment_method.rs
Normal file
@ -0,0 +1,14 @@
|
||||
use rocket::FromForm;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(
|
||||
Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, FromForm,
|
||||
)]
|
||||
pub struct CommitmentMethod {
|
||||
pub method: String,
|
||||
}
|
||||
impl CommitmentMethod {
|
||||
pub fn new(method: String) -> Self {
|
||||
CommitmentMethod { method }
|
||||
}
|
||||
}
|
28
src/models/condition_cap.rs
Normal file
28
src/models/condition_cap.rs
Normal file
@ -0,0 +1,28 @@
|
||||
use rocket::FromForm;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::role::TransactionMode;
|
||||
|
||||
#[derive(
|
||||
Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, FromForm,
|
||||
)]
|
||||
pub struct ConditionCap {
|
||||
pub role_deposit: String,
|
||||
pub role_transaction: TransactionMode,
|
||||
}
|
||||
|
||||
impl ConditionCap {
|
||||
pub fn new(role_deposit: String, role_transaction: TransactionMode) -> Self {
|
||||
ConditionCap {
|
||||
role_deposit,
|
||||
role_transaction,
|
||||
}
|
||||
}
|
||||
// Affiche les informations de la structure
|
||||
pub fn display_info(&self) {
|
||||
println!("ConditionCap:");
|
||||
println!("Role Deposit: {}", self.role_deposit);
|
||||
println!("Role Transaction:");
|
||||
self.role_transaction.display_info(); // Appelle display_info sur role_transaction
|
||||
}
|
||||
}
|
26
src/models/condition_commitment.rs
Normal file
26
src/models/condition_commitment.rs
Normal file
@ -0,0 +1,26 @@
|
||||
use rocket::FromForm;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::role::TransactionMode;
|
||||
#[derive(
|
||||
Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, FromForm,
|
||||
)]
|
||||
pub struct ConditionCommitment {
|
||||
pub role_artefact: String,
|
||||
pub role_transaction: TransactionMode,
|
||||
}
|
||||
|
||||
impl ConditionCommitment {
|
||||
pub fn new(role_artefact: String, role_transaction: TransactionMode) -> Self {
|
||||
ConditionCommitment {
|
||||
role_artefact,
|
||||
role_transaction,
|
||||
}
|
||||
}
|
||||
pub fn display_info(&self) {
|
||||
println!("ConditionCommitment:");
|
||||
println!("Role Artefact: {}", self.role_artefact);
|
||||
println!("Role Transaction:");
|
||||
self.role_transaction.display_info(); // Appelle display_info sur role_transaction
|
||||
}
|
||||
}
|
27
src/models/condition_deposit.rs
Normal file
27
src/models/condition_deposit.rs
Normal file
@ -0,0 +1,27 @@
|
||||
use rocket::FromForm;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::role::TransactionMode;
|
||||
#[derive(
|
||||
Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, FromForm,
|
||||
)]
|
||||
|
||||
pub struct ConditionDeposit {
|
||||
pub role_deposit: String,
|
||||
pub role_transaction: TransactionMode,
|
||||
}
|
||||
|
||||
impl ConditionDeposit {
|
||||
pub fn new(role_deposit: String, role_transaction: TransactionMode) -> Self {
|
||||
ConditionDeposit {
|
||||
role_deposit,
|
||||
role_transaction,
|
||||
}
|
||||
}
|
||||
pub fn display_info(&self) {
|
||||
println!("ConditionDeposit:");
|
||||
println!("Role Deposit: {}", self.role_deposit);
|
||||
println!("Role Transaction:");
|
||||
self.role_transaction.display_info(); // Appelle display_info sur role_transaction
|
||||
}
|
||||
}
|
22
src/models/condition_orchestration.rs
Normal file
22
src/models/condition_orchestration.rs
Normal file
@ -0,0 +1,22 @@
|
||||
use rocket::FromForm;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(
|
||||
Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, FromForm,
|
||||
)]
|
||||
|
||||
pub struct ConditionOrchestration {
|
||||
pub role_ok: String,
|
||||
pub role_ko: String,
|
||||
}
|
||||
|
||||
impl ConditionOrchestration {
|
||||
pub fn new(role_ok: String, role_ko: String) -> Self {
|
||||
ConditionOrchestration { role_ok, role_ko }
|
||||
}
|
||||
pub fn display_info(&self) {
|
||||
println!("ConditionOrchestration:");
|
||||
println!("Role OK: {}", self.role_ok);
|
||||
println!("Role KO: {}", self.role_ko);
|
||||
}
|
||||
}
|
28
src/models/condition_payment.rs
Normal file
28
src/models/condition_payment.rs
Normal file
@ -0,0 +1,28 @@
|
||||
use rocket::FromForm;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::role::TransactionMode;
|
||||
|
||||
#[derive(
|
||||
Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, FromForm,
|
||||
)]
|
||||
|
||||
pub struct ConditionPayment {
|
||||
pub role_payment: String,
|
||||
pub role_transaction: TransactionMode,
|
||||
}
|
||||
|
||||
impl ConditionPayment {
|
||||
pub fn new(role_payment: String, role_transaction: TransactionMode) -> Self {
|
||||
ConditionPayment {
|
||||
role_payment,
|
||||
role_transaction,
|
||||
}
|
||||
}
|
||||
pub fn display_info(&self) {
|
||||
println!("ConditionPayment:");
|
||||
println!("Role Payment: {}", self.role_payment);
|
||||
println!("Role Transaction:");
|
||||
self.role_transaction.display_info(); // Appelle display_info sur role_transaction
|
||||
}
|
||||
}
|
144
src/models/condition_prd_address_set.rs
Normal file
144
src/models/condition_prd_address_set.rs
Normal file
@ -0,0 +1,144 @@
|
||||
use rocket::FromForm;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(
|
||||
Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, FromForm,
|
||||
)]
|
||||
|
||||
pub struct ConditionPrdAddressSet {
|
||||
pub from_role: String,
|
||||
pub prd_sp_address_list: Vec<String>,
|
||||
pub prd_sp_address_required_list: Vec<String>,
|
||||
pub prd_sp_address_quota: i32,
|
||||
pub prd_prd_value_ok_list: Vec<String>,
|
||||
pub prd_value_ko_list: Vec<String>,
|
||||
pub prd_value_none_list: Vec<String>,
|
||||
pub prd_sp_address_value_min: i64,
|
||||
pub prd_sp_address_value_min_per: i64,
|
||||
pub prd_sp_address_value_min_ok: bool,
|
||||
pub prd_sp_adddress_value_ok_min_per: i64,
|
||||
pub prd_sp_address_value_ok_max: i64,
|
||||
pub prd_sp_adderss_value_ko_max_per: i64,
|
||||
pub prd_sp_address_value_none_max: i64,
|
||||
pub prd_sp_adderss_value_none_max_per: i64,
|
||||
pub prd_sp_address_score_min: i32,
|
||||
pub prd_sp_address_score_min_min_required: i32,
|
||||
pub prd_sp_address_score_min_min_ok: bool,
|
||||
pub prd_sp_address_score_min_min_per: i64,
|
||||
pub prd_value_auto_ok: bool,
|
||||
pub prd_value_auto_ko: bool,
|
||||
pub prd_value_auto_none: bool,
|
||||
}
|
||||
|
||||
impl ConditionPrdAddressSet {
|
||||
// Constructor for PrdAddressSet with all fields
|
||||
pub fn new(
|
||||
from_role: String,
|
||||
prd_sp_address_list: Vec<String>,
|
||||
prd_sp_address_required_list: Vec<String>,
|
||||
prd_sp_address_quota: i32,
|
||||
prd_prd_value_ok_list: Vec<String>,
|
||||
prd_value_ko_list: Vec<String>,
|
||||
prd_value_none_list: Vec<String>,
|
||||
prd_sp_address_value_min: i64,
|
||||
prd_sp_address_value_min_per: i64,
|
||||
prd_sp_address_value_min_ok: bool,
|
||||
prd_sp_adddress_value_ok_min_per: i64,
|
||||
prd_sp_address_value_ok_max: i64,
|
||||
prd_sp_adderss_value_ko_max_per: i64,
|
||||
prd_sp_address_value_none_max: i64,
|
||||
prd_sp_adderss_value_none_max_per: i64,
|
||||
prd_sp_address_score_min: i32,
|
||||
prd_sp_address_score_min_min_required: i32,
|
||||
prd_sp_address_score_min_min_ok: bool,
|
||||
prd_sp_address_score_min_min_per: i64,
|
||||
prd_value_auto_ok: bool,
|
||||
prd_value_auto_ko: bool,
|
||||
prd_value_auto_none: bool,
|
||||
) -> Self {
|
||||
ConditionPrdAddressSet {
|
||||
from_role,
|
||||
prd_sp_address_list,
|
||||
prd_sp_address_required_list,
|
||||
prd_sp_address_quota,
|
||||
prd_prd_value_ok_list,
|
||||
prd_value_ko_list,
|
||||
prd_value_none_list,
|
||||
prd_sp_address_value_min,
|
||||
prd_sp_address_value_min_per,
|
||||
prd_sp_address_value_min_ok,
|
||||
prd_sp_adddress_value_ok_min_per,
|
||||
prd_sp_address_value_ok_max,
|
||||
prd_sp_adderss_value_ko_max_per,
|
||||
prd_sp_address_value_none_max,
|
||||
prd_sp_adderss_value_none_max_per,
|
||||
prd_sp_address_score_min,
|
||||
prd_sp_address_score_min_min_required,
|
||||
prd_sp_address_score_min_min_ok,
|
||||
prd_sp_address_score_min_min_per,
|
||||
prd_value_auto_ok,
|
||||
prd_value_auto_ko,
|
||||
prd_value_auto_none,
|
||||
}
|
||||
}
|
||||
pub fn display_info(&self) {
|
||||
println!("ConditionPrdAddressSet:");
|
||||
println!("From Role: {}", self.from_role);
|
||||
println!("SP Address List: {:?}", self.prd_sp_address_list);
|
||||
println!(
|
||||
"SP Address Required List: {:?}",
|
||||
self.prd_sp_address_required_list
|
||||
);
|
||||
println!("SP Address Quota: {}", self.prd_sp_address_quota);
|
||||
println!("PRD Value OK List: {:?}", self.prd_prd_value_ok_list);
|
||||
println!("Value KO List: {:?}", self.prd_value_ko_list);
|
||||
println!("Value None List: {:?}", self.prd_value_none_list);
|
||||
println!("SP Address Value Min: {}", self.prd_sp_address_value_min);
|
||||
println!(
|
||||
"SP Address Value Min Percentage: {}",
|
||||
self.prd_sp_address_value_min_per
|
||||
);
|
||||
println!(
|
||||
"SP Address Value Min OK: {}",
|
||||
self.prd_sp_address_value_min_ok
|
||||
);
|
||||
println!(
|
||||
"SP Address Value OK Min Percentage: {}",
|
||||
self.prd_sp_adddress_value_ok_min_per
|
||||
);
|
||||
println!(
|
||||
"SP Address Value OK Max: {}",
|
||||
self.prd_sp_address_value_ok_max
|
||||
);
|
||||
println!(
|
||||
"SP Address Value KO Max Percentage: {}",
|
||||
self.prd_sp_adderss_value_ko_max_per
|
||||
);
|
||||
println!(
|
||||
"SP Address Value None Max: {}",
|
||||
self.prd_sp_address_value_none_max
|
||||
);
|
||||
println!(
|
||||
"SP Address Value None Max Percentage: {}",
|
||||
self.prd_sp_adderss_value_none_max_per
|
||||
);
|
||||
println!("SP Address Score Min: {}", self.prd_sp_address_score_min);
|
||||
println!(
|
||||
"SP Address Score Min Required: {}",
|
||||
self.prd_sp_address_score_min_min_required
|
||||
);
|
||||
println!(
|
||||
"SP Address Score Min OK: {}",
|
||||
self.prd_sp_address_score_min_min_ok
|
||||
);
|
||||
println!(
|
||||
"SP Address Score Min Percentage: {}",
|
||||
self.prd_sp_address_score_min_min_per
|
||||
);
|
||||
println!("Value Auto OK: {}", self.prd_value_auto_ok);
|
||||
println!("Value Auto KO: {}", self.prd_value_auto_ko);
|
||||
println!("Value Auto None: {}", self.prd_value_auto_none);
|
||||
}
|
||||
|
||||
// Methods for manipulating the struct can be added here as needed.
|
||||
}
|
49
src/models/condition_publish.rs
Normal file
49
src/models/condition_publish.rs
Normal file
@ -0,0 +1,49 @@
|
||||
use rocket::FromForm;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::metadata::Amount;
|
||||
#[derive(
|
||||
Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, FromForm,
|
||||
)]
|
||||
|
||||
pub struct ConditionPublish {
|
||||
pub pcd_data_size_max_unit: String,
|
||||
pub pcd_data_size_max_total: i64,
|
||||
pub pcd_number_min: i32,
|
||||
pub pcd_number_max: i32,
|
||||
pub pcd_amount_max_total: Amount,
|
||||
pub prd_waiting_timeout: u64,
|
||||
pub pcd_waiting_timeout: u64,
|
||||
}
|
||||
|
||||
impl ConditionPublish {
|
||||
pub fn new(
|
||||
pcd_data_size_max_unit: String,
|
||||
pcd_data_size_max_total: i64,
|
||||
pcd_number_min: i32,
|
||||
pcd_number_max: i32,
|
||||
pcd_amount_max_total: Amount,
|
||||
prd_waiting_timeout: u64,
|
||||
pcd_waiting_timeout: u64,
|
||||
) -> Self {
|
||||
ConditionPublish {
|
||||
pcd_data_size_max_unit,
|
||||
pcd_data_size_max_total,
|
||||
pcd_number_min,
|
||||
pcd_number_max,
|
||||
pcd_amount_max_total,
|
||||
prd_waiting_timeout,
|
||||
pcd_waiting_timeout,
|
||||
}
|
||||
}
|
||||
pub fn display_info(&self) {
|
||||
println!("ConditionPublish:");
|
||||
println!("PCD Data Size Max Unit: {}", self.pcd_data_size_max_unit);
|
||||
println!("PCD Data Size Max Total: {}", self.pcd_data_size_max_total);
|
||||
println!("PCD Number Min: {}", self.pcd_number_min);
|
||||
println!("PCD Number Max: {}", self.pcd_number_max);
|
||||
self.pcd_amount_max_total.display_info();
|
||||
println!("PRD Waiting Timeout: {}", self.prd_waiting_timeout);
|
||||
println!("PCD Waiting Timeout: {}", self.pcd_waiting_timeout);
|
||||
}
|
||||
}
|
11
src/models/deposit_method.rs
Normal file
11
src/models/deposit_method.rs
Normal file
@ -0,0 +1,11 @@
|
||||
use rocket::FromForm;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(
|
||||
Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, FromForm,
|
||||
)]
|
||||
|
||||
pub struct DepositMethod {
|
||||
pub method: String,
|
||||
}
|
||||
impl DepositMethod {}
|
97
src/models/item.rs
Normal file
97
src/models/item.rs
Normal file
@ -0,0 +1,97 @@
|
||||
use rocket::FromForm;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use uuid::Uuid;
|
||||
|
||||
use super::{
|
||||
key_encryption::KeyEncryption, metadata_contract_public::MetadataContractPublic,
|
||||
metadata_private::MetadataPrivate, metadata_role_confidential::MetadataRoleConfidential,
|
||||
pcd_item_enc::PcdItemEnc,
|
||||
};
|
||||
|
||||
#[derive(
|
||||
Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, FromForm,
|
||||
)]
|
||||
|
||||
pub struct Item {
|
||||
pub uuid: String,
|
||||
pub version: i64,
|
||||
pub hash: Option<String>,
|
||||
pub item_type: String, // `type` is a reserved keyword in Rust, renamed to `item_type`
|
||||
pub name: String,
|
||||
pub pagination_number_per_pcd: u32,
|
||||
pub metadata_contract_public: MetadataContractPublic,
|
||||
pub metadata_role_confidential: MetadataRoleConfidential,
|
||||
pub metadata_private: MetadataPrivate,
|
||||
}
|
||||
|
||||
impl Item {
|
||||
pub fn new(
|
||||
version: i64,
|
||||
item_type: String,
|
||||
name: String,
|
||||
pagination_number_per_pcd: u32,
|
||||
metadata_contract_public: MetadataContractPublic,
|
||||
metadata_role_confidential: MetadataRoleConfidential,
|
||||
metadata_private: MetadataPrivate,
|
||||
) -> Self {
|
||||
let uuid: String = Uuid::new_v4().to_string();
|
||||
Item {
|
||||
uuid,
|
||||
version,
|
||||
item_type,
|
||||
name,
|
||||
pagination_number_per_pcd,
|
||||
metadata_contract_public,
|
||||
metadata_role_confidential,
|
||||
metadata_private,
|
||||
hash: None,
|
||||
}
|
||||
}
|
||||
pub fn display_info(&self) {
|
||||
println!("Item:");
|
||||
println!("UUID: {}", self.uuid);
|
||||
println!("Version: {}", self.version);
|
||||
println!("Item Type: {}", self.item_type);
|
||||
println!("Name: {}", self.name);
|
||||
println!(
|
||||
"Pagination Number Per PCD: {}",
|
||||
self.pagination_number_per_pcd
|
||||
);
|
||||
|
||||
println!("Metadata Contract Public:");
|
||||
self.metadata_contract_public.display_info(); // Display information for `metadata_contract_public`
|
||||
|
||||
println!("Metadata Role Confidential:");
|
||||
self.metadata_role_confidential.display_info(); // Display information for `metadata_role_confidential`
|
||||
|
||||
println!("Metadata Private:");
|
||||
self.metadata_private.display_info(); // Display information for `metadata_private`
|
||||
}
|
||||
|
||||
pub fn enc(
|
||||
&self,
|
||||
process_public_enc_key: KeyEncryption,
|
||||
member_private_enc_key: KeyEncryption,
|
||||
) -> PcdItemEnc {
|
||||
let enc_metadata_contract_public = self
|
||||
.metadata_contract_public
|
||||
.enc_list(process_public_enc_key);
|
||||
|
||||
let enc_metadata_role_confidential = self.metadata_role_confidential.enc_list();
|
||||
|
||||
let enc_metadata_private = self.metadata_private.enc_list(member_private_enc_key);
|
||||
|
||||
PcdItemEnc::new(
|
||||
self.version,
|
||||
self.item_type.clone(),
|
||||
self.name.clone(),
|
||||
self.pagination_number_per_pcd,
|
||||
enc_metadata_contract_public,
|
||||
enc_metadata_role_confidential,
|
||||
enc_metadata_private,
|
||||
)
|
||||
}
|
||||
|
||||
// Additional methods for Item can be added here
|
||||
}
|
134
src/models/item_artefact.rs
Normal file
134
src/models/item_artefact.rs
Normal file
@ -0,0 +1,134 @@
|
||||
use rocket::FromForm;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::json;
|
||||
use std::hash::Hash;
|
||||
|
||||
use super::item::Item;
|
||||
use super::key_encryption::KeyEncryption;
|
||||
use super::pcd_item_enc_attribute_private::PcdItemEncAttributePrivate;
|
||||
use super::pcd_item_enc_attribute_public::PcdItemEncAttributePublic;
|
||||
use super::pcd_item_enc_attribute_role_confidential::PcdItemEncAttributeRoleConfidential;
|
||||
use super::pcd_item_generic_enc::PcdItemGenericEnc;
|
||||
|
||||
#[derive(
|
||||
Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, FromForm, Hash, PartialOrd, Ord,
|
||||
)]
|
||||
pub struct ItemArtefact {
|
||||
pub item: Item,
|
||||
pub public_attribute_group: Vec<String>, // Assuming list of attributes
|
||||
pub role_confidential_attribute_group: Vec<String>,
|
||||
pub private_attribute_group: Vec<String>,
|
||||
}
|
||||
|
||||
impl ItemArtefact {
|
||||
pub fn new(
|
||||
item: Item,
|
||||
public_attribute_group: Vec<String>,
|
||||
role_confidential_attribute_group: Vec<String>,
|
||||
private_attribute_group: Vec<String>,
|
||||
) -> Self {
|
||||
ItemArtefact {
|
||||
item,
|
||||
public_attribute_group,
|
||||
role_confidential_attribute_group,
|
||||
private_attribute_group,
|
||||
}
|
||||
}
|
||||
pub fn enc_public_attribute_group(
|
||||
&self,
|
||||
process_public_enc_key: KeyEncryption,
|
||||
) -> Vec<PcdItemEncAttributePublic> {
|
||||
let mut enc_attribute_list: Vec<PcdItemEncAttributePublic> = Vec::new();
|
||||
|
||||
let mut count = 0;
|
||||
for public_attribute in &self.public_attribute_group {
|
||||
let name = "index".to_owned() + &count.to_string();
|
||||
let value = serde_json::to_value(public_attribute).unwrap_or_else(|_| json!({}));
|
||||
let enc_attribute =
|
||||
PcdItemEncAttributePublic::new(name, process_public_enc_key.enc(value));
|
||||
enc_attribute_list.push(enc_attribute);
|
||||
count += 1;
|
||||
}
|
||||
|
||||
enc_attribute_list
|
||||
}
|
||||
pub fn enc_role_confidential_attribute_group(
|
||||
&self,
|
||||
) -> Vec<PcdItemEncAttributeRoleConfidential> {
|
||||
let mut enc_attribute_list: Vec<PcdItemEncAttributeRoleConfidential> = Vec::new();
|
||||
|
||||
let mut count = 0;
|
||||
for role_confidential_attribute in &self.role_confidential_attribute_group {
|
||||
let name = "index".to_owned() + &count.to_string();
|
||||
let value =
|
||||
serde_json::to_value(role_confidential_attribute).unwrap_or_else(|_| json!({}));
|
||||
let mut role_confidential_attribute_key =
|
||||
KeyEncryption::new(Some(name.clone()), None, None);
|
||||
if let Ok(_new) = role_confidential_attribute_key.key_new_random() {
|
||||
let enc_attribute = PcdItemEncAttributeRoleConfidential::new(
|
||||
name,
|
||||
role_confidential_attribute_key.enc(value),
|
||||
role_confidential_attribute_key,
|
||||
);
|
||||
enc_attribute_list.push(enc_attribute);
|
||||
}
|
||||
count += 1;
|
||||
}
|
||||
|
||||
enc_attribute_list
|
||||
}
|
||||
pub fn enc_private_attribute_group(
|
||||
&self,
|
||||
member_private_enc_key: KeyEncryption,
|
||||
) -> Vec<PcdItemEncAttributePrivate> {
|
||||
let mut enc_attribute_list: Vec<PcdItemEncAttributePrivate> = Vec::new();
|
||||
|
||||
let mut count = 0;
|
||||
for private_attribute in &self.public_attribute_group {
|
||||
let name = "index".to_owned() + &count.to_string();
|
||||
let value = serde_json::to_value(private_attribute).unwrap_or_else(|_| json!({}));
|
||||
let enc_attribute =
|
||||
PcdItemEncAttributePrivate::new(name, member_private_enc_key.enc(value));
|
||||
enc_attribute_list.push(enc_attribute);
|
||||
count += 1;
|
||||
}
|
||||
|
||||
enc_attribute_list
|
||||
}
|
||||
|
||||
pub fn enc(
|
||||
&self,
|
||||
process_public_enc_key: KeyEncryption,
|
||||
member_private_enc_key: KeyEncryption,
|
||||
) -> PcdItemGenericEnc {
|
||||
let enc_metadata_contract_public =
|
||||
self.enc_public_attribute_group(process_public_enc_key.clone());
|
||||
|
||||
let enc_role_confidential_attribute_group = self.enc_role_confidential_attribute_group();
|
||||
|
||||
let enc_metadata_private = self.enc_private_attribute_group(member_private_enc_key.clone());
|
||||
|
||||
PcdItemGenericEnc::new(
|
||||
self.item
|
||||
.enc(process_public_enc_key, member_private_enc_key),
|
||||
Some(enc_metadata_contract_public),
|
||||
Some(enc_role_confidential_attribute_group),
|
||||
Some(enc_metadata_private),
|
||||
)
|
||||
}
|
||||
pub fn display_info(&self) {
|
||||
println!("ItemArtefact:");
|
||||
println!("Item:");
|
||||
self.item.display_info(); // Appelle display_info sur item
|
||||
|
||||
println!("Public Attribute Group: {:?}", self.public_attribute_group);
|
||||
println!(
|
||||
"Role Confidential Attribute Group: {:?}",
|
||||
self.role_confidential_attribute_group
|
||||
);
|
||||
println!(
|
||||
"Private Attribute Group: {:?}",
|
||||
self.private_attribute_group
|
||||
);
|
||||
}
|
||||
}
|
248
src/models/item_commitment.rs
Normal file
248
src/models/item_commitment.rs
Normal file
@ -0,0 +1,248 @@
|
||||
use rocket::FromForm;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::{
|
||||
item::Item, key_encryption::KeyEncryption,
|
||||
pcd_item_enc_attribute_private::PcdItemEncAttributePrivate,
|
||||
pcd_item_enc_attribute_public::PcdItemEncAttributePublic,
|
||||
pcd_item_enc_attribute_role_confidential::PcdItemEncAttributeRoleConfidential,
|
||||
pcd_item_generic_enc::PcdItemGenericEnc,
|
||||
};
|
||||
|
||||
#[derive(
|
||||
Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, FromForm,
|
||||
)]
|
||||
|
||||
pub struct ItemCommitmentPublicAttributeGroup {
|
||||
pub for_sp_address_list: Vec<String>,
|
||||
pub goal_list: Vec<String>,
|
||||
pub provider_type: String,
|
||||
pub commitment_pcd_hash_list: Vec<String>,
|
||||
pub ref_item_hash_list: Vec<String>,
|
||||
pub ref_pcd_hash_list: Vec<String>,
|
||||
pub payload_public_list: Vec<String>,
|
||||
}
|
||||
|
||||
impl ItemCommitmentPublicAttributeGroup {
|
||||
pub fn new(
|
||||
for_sp_address_list: Vec<String>,
|
||||
goal_list: Vec<String>,
|
||||
provider_type: String,
|
||||
commitment_pcd_hash_list: Vec<String>,
|
||||
ref_item_hash_list: Vec<String>,
|
||||
ref_pcd_hash_list: Vec<String>,
|
||||
payload_public_list: Vec<String>,
|
||||
) -> Self {
|
||||
ItemCommitmentPublicAttributeGroup {
|
||||
for_sp_address_list,
|
||||
goal_list,
|
||||
provider_type,
|
||||
commitment_pcd_hash_list,
|
||||
ref_item_hash_list,
|
||||
ref_pcd_hash_list,
|
||||
payload_public_list,
|
||||
}
|
||||
}
|
||||
pub fn enc_group(
|
||||
&self,
|
||||
process_public_enc_key: KeyEncryption,
|
||||
) -> Vec<PcdItemEncAttributePublic> {
|
||||
let mut enc_attribute_list: Vec<PcdItemEncAttributePublic> = Vec::new();
|
||||
|
||||
let for_sp_address_list_enc = PcdItemEncAttributePublic::new(
|
||||
"for_sp_address_list".to_owned(),
|
||||
process_public_enc_key.enc_vec_string(self.for_sp_address_list.clone()),
|
||||
);
|
||||
enc_attribute_list.push(for_sp_address_list_enc);
|
||||
|
||||
let goal_list_enc = PcdItemEncAttributePublic::new(
|
||||
"goal_list".to_owned(),
|
||||
process_public_enc_key.enc_vec_string(self.goal_list.clone()),
|
||||
);
|
||||
enc_attribute_list.push(goal_list_enc);
|
||||
|
||||
let provider_type_enc = PcdItemEncAttributePublic::new(
|
||||
"provider_type".to_owned(),
|
||||
process_public_enc_key.enc_string(self.provider_type.clone()),
|
||||
);
|
||||
enc_attribute_list.push(provider_type_enc);
|
||||
|
||||
let commitment_pcd_hash_list_enc = PcdItemEncAttributePublic::new(
|
||||
"commitment_pcd_hash_list".to_owned(),
|
||||
process_public_enc_key.enc_vec_string(self.commitment_pcd_hash_list.clone()),
|
||||
);
|
||||
enc_attribute_list.push(commitment_pcd_hash_list_enc);
|
||||
|
||||
let ref_item_hash_list_enc = PcdItemEncAttributePublic::new(
|
||||
"ref_item_hash_list".to_owned(),
|
||||
process_public_enc_key.enc_vec_string(self.ref_item_hash_list.clone()),
|
||||
);
|
||||
enc_attribute_list.push(ref_item_hash_list_enc);
|
||||
|
||||
let ref_pcd_hash_list_enc = PcdItemEncAttributePublic::new(
|
||||
"ref_pcd_hash_list".to_owned(),
|
||||
process_public_enc_key.enc_vec_string(self.ref_pcd_hash_list.clone()),
|
||||
);
|
||||
enc_attribute_list.push(ref_pcd_hash_list_enc);
|
||||
|
||||
let payload_public_list_enc = PcdItemEncAttributePublic::new(
|
||||
"payload_public_list".to_owned(),
|
||||
process_public_enc_key.enc_vec_string(self.payload_public_list.clone()),
|
||||
);
|
||||
enc_attribute_list.push(payload_public_list_enc);
|
||||
|
||||
enc_attribute_list
|
||||
}
|
||||
pub fn display_info(&self) {
|
||||
println!("ItemCommitmentPublicAttributeGroup:");
|
||||
println!("For SP Address List: {:?}", self.for_sp_address_list);
|
||||
println!("Goal List: {:?}", self.goal_list);
|
||||
println!("Provider Type: {}", self.provider_type);
|
||||
println!(
|
||||
"Commitment PCD Hash List: {:?}",
|
||||
self.commitment_pcd_hash_list
|
||||
);
|
||||
println!("Ref Item Hash List: {:?}", self.ref_item_hash_list);
|
||||
println!("Ref PCD Hash List: {:?}", self.ref_pcd_hash_list);
|
||||
println!("Payload Public List: {:?}", self.payload_public_list);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(
|
||||
Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, FromForm,
|
||||
)]
|
||||
|
||||
pub struct ItemCommitmentRoleConfidentialAttributeGroup {
|
||||
pub payload_list_confidential: Vec<String>,
|
||||
}
|
||||
|
||||
impl ItemCommitmentRoleConfidentialAttributeGroup {
|
||||
pub fn new(payload_list_confidential: Vec<String>) -> Self {
|
||||
ItemCommitmentRoleConfidentialAttributeGroup {
|
||||
payload_list_confidential,
|
||||
}
|
||||
}
|
||||
pub fn enc_group(&self) -> Vec<PcdItemEncAttributeRoleConfidential> {
|
||||
let mut enc_attribute_list: Vec<PcdItemEncAttributeRoleConfidential> = Vec::new();
|
||||
|
||||
let mut payload_list_confidential_key =
|
||||
KeyEncryption::new(Some("payload_list_confidential".to_owned()), None, None);
|
||||
if let Ok(_new) = payload_list_confidential_key.key_new_random() {
|
||||
let payload_list_confidential_enc = PcdItemEncAttributeRoleConfidential::new(
|
||||
"payload_list_confidential".to_owned(),
|
||||
payload_list_confidential_key
|
||||
.enc_vec_string(self.payload_list_confidential.clone()),
|
||||
payload_list_confidential_key,
|
||||
);
|
||||
enc_attribute_list.push(payload_list_confidential_enc);
|
||||
}
|
||||
|
||||
return enc_attribute_list;
|
||||
}
|
||||
pub fn display_info(&self) {
|
||||
println!("ItemCommitmentRoleConfidentialAttributeGroup:");
|
||||
for (index, payload) in self.payload_list_confidential.iter().enumerate() {
|
||||
println!("Confidential Payload {}: {}", index + 1, payload);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(
|
||||
Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, FromForm,
|
||||
)]
|
||||
|
||||
pub struct ItemCommitmentPrivateAttributeGroup {
|
||||
pub payload_list_private: Vec<String>,
|
||||
}
|
||||
|
||||
impl ItemCommitmentPrivateAttributeGroup {
|
||||
pub fn new(payload_list_private: Vec<String>) -> Self {
|
||||
ItemCommitmentPrivateAttributeGroup {
|
||||
payload_list_private,
|
||||
}
|
||||
}
|
||||
pub fn enc_group(&self, member_enc_key: KeyEncryption) -> Vec<PcdItemEncAttributePrivate> {
|
||||
let mut enc_attribute_list: Vec<PcdItemEncAttributePrivate> = Vec::new();
|
||||
|
||||
let payload_list_private_enc = PcdItemEncAttributePrivate::new(
|
||||
"payload_list_private".to_owned(),
|
||||
member_enc_key.enc_vec_string(self.payload_list_private.clone()),
|
||||
);
|
||||
enc_attribute_list.push(payload_list_private_enc);
|
||||
|
||||
enc_attribute_list
|
||||
}
|
||||
pub fn display_info(&self) {
|
||||
println!("ItemCommitmentRoleConfidentialAttributeGroup:");
|
||||
for (index, payload) in self.payload_list_private.iter().enumerate() {
|
||||
println!("Private Payload {}: {}", index + 1, payload);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(
|
||||
Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, FromForm,
|
||||
)]
|
||||
|
||||
pub struct ItemCommitment {
|
||||
pub item: Item,
|
||||
pub public_attribute_group: ItemCommitmentPublicAttributeGroup,
|
||||
pub role_confidential_attribute_group: ItemCommitmentRoleConfidentialAttributeGroup,
|
||||
pub private_attribute_group: ItemCommitmentPrivateAttributeGroup,
|
||||
}
|
||||
|
||||
impl ItemCommitment {
|
||||
pub const ITEM_NAME: &'static str = "commitment";
|
||||
pub fn new(
|
||||
mut item: Item,
|
||||
public_attribute_group: ItemCommitmentPublicAttributeGroup,
|
||||
role_confidential_attribute_group: ItemCommitmentRoleConfidentialAttributeGroup,
|
||||
private_attribute_group: ItemCommitmentPrivateAttributeGroup,
|
||||
) -> Self {
|
||||
item.name = Self::ITEM_NAME.to_string();
|
||||
ItemCommitment {
|
||||
item,
|
||||
public_attribute_group,
|
||||
role_confidential_attribute_group,
|
||||
private_attribute_group,
|
||||
}
|
||||
}
|
||||
pub fn enc(
|
||||
&self,
|
||||
process_public_enc_key: KeyEncryption,
|
||||
member_private_enc_key: KeyEncryption,
|
||||
) -> PcdItemGenericEnc {
|
||||
let enc_metadata_contract_public = self
|
||||
.public_attribute_group
|
||||
.enc_group(process_public_enc_key.clone());
|
||||
|
||||
let enc_role_confidential_attribute_group =
|
||||
self.role_confidential_attribute_group.enc_group();
|
||||
|
||||
let enc_metadata_private = self
|
||||
.private_attribute_group
|
||||
.enc_group(member_private_enc_key.clone());
|
||||
|
||||
PcdItemGenericEnc::new(
|
||||
self.item
|
||||
.enc(process_public_enc_key, member_private_enc_key),
|
||||
Some(enc_metadata_contract_public),
|
||||
Some(enc_role_confidential_attribute_group),
|
||||
Some(enc_metadata_private),
|
||||
)
|
||||
}
|
||||
pub fn display_info(&self) {
|
||||
println!("ItemCommitment:");
|
||||
println!("Item:");
|
||||
self.item.display_info(); // Affiche les informations de `item`
|
||||
|
||||
println!("Public Attribute Group:");
|
||||
self.public_attribute_group.display_info(); // Affiche les informations de `public_attribute_group`
|
||||
|
||||
println!("Role Confidential Attribute Group:");
|
||||
self.role_confidential_attribute_group.display_info(); // Affiche les informations de `role_confidential_attribute_group`
|
||||
|
||||
println!("Private Attribute Group:");
|
||||
self.private_attribute_group.display_info(); // Affiche les informations de `private_attribute_group`
|
||||
}
|
||||
}
|
286
src/models/item_deposit.rs
Normal file
286
src/models/item_deposit.rs
Normal file
@ -0,0 +1,286 @@
|
||||
use rocket::FromForm;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::{
|
||||
item::Item, key_encryption::KeyEncryption,
|
||||
pcd_item_enc_attribute_private::PcdItemEncAttributePrivate,
|
||||
pcd_item_enc_attribute_public::PcdItemEncAttributePublic,
|
||||
pcd_item_enc_attribute_role_confidential::PcdItemEncAttributeRoleConfidential,
|
||||
pcd_item_generic_enc::PcdItemGenericEnc,
|
||||
};
|
||||
|
||||
#[derive(
|
||||
Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, FromForm,
|
||||
)]
|
||||
|
||||
pub struct ItemDepositPublicAttributeGroup {
|
||||
pub for_sp_address_list: Vec<String>,
|
||||
pub for_address_list: Vec<String>,
|
||||
pub goal_list: Vec<String>,
|
||||
pub provider_type: String,
|
||||
pub ref_item_hash_list: Vec<String>,
|
||||
pub ref_pcd_hash_list: Vec<String>,
|
||||
pub payload_list_public: Vec<String>,
|
||||
pub audit_code_list_public: Vec<String>,
|
||||
}
|
||||
|
||||
impl ItemDepositPublicAttributeGroup {
|
||||
pub fn new(
|
||||
for_sp_address_list: Vec<String>,
|
||||
for_address_list: Vec<String>,
|
||||
goal_list: Vec<String>,
|
||||
provider_type: String,
|
||||
ref_item_hash_list: Vec<String>,
|
||||
ref_pcd_hash_list: Vec<String>,
|
||||
payload_list_public: Vec<String>,
|
||||
audit_code_list_public: Vec<String>,
|
||||
) -> Self {
|
||||
ItemDepositPublicAttributeGroup {
|
||||
for_sp_address_list,
|
||||
for_address_list,
|
||||
goal_list,
|
||||
provider_type,
|
||||
ref_item_hash_list,
|
||||
ref_pcd_hash_list,
|
||||
payload_list_public,
|
||||
audit_code_list_public,
|
||||
}
|
||||
}
|
||||
pub fn enc_group(
|
||||
&self,
|
||||
process_public_enc_key: KeyEncryption,
|
||||
) -> Vec<PcdItemEncAttributePublic> {
|
||||
let mut enc_attribute_list: Vec<PcdItemEncAttributePublic> = Vec::new();
|
||||
|
||||
let for_sp_address_list_enc = PcdItemEncAttributePublic::new(
|
||||
"for_sp_address_list".to_owned(),
|
||||
process_public_enc_key.enc_vec_string(self.for_sp_address_list.clone()),
|
||||
);
|
||||
enc_attribute_list.push(for_sp_address_list_enc);
|
||||
|
||||
let for_address_list_enc = PcdItemEncAttributePublic::new(
|
||||
"for_address_list".to_owned(),
|
||||
process_public_enc_key.enc_vec_string(self.for_address_list.clone()),
|
||||
);
|
||||
enc_attribute_list.push(for_address_list_enc);
|
||||
|
||||
let goal_list_enc = PcdItemEncAttributePublic::new(
|
||||
"goal_list".to_owned(),
|
||||
process_public_enc_key.enc_vec_string(self.goal_list.clone()),
|
||||
);
|
||||
enc_attribute_list.push(goal_list_enc);
|
||||
|
||||
let provider_type_enc = PcdItemEncAttributePublic::new(
|
||||
"provider_type".to_owned(),
|
||||
process_public_enc_key.enc_string(self.provider_type.clone()),
|
||||
);
|
||||
enc_attribute_list.push(provider_type_enc);
|
||||
|
||||
let ref_item_hash_list_enc = PcdItemEncAttributePublic::new(
|
||||
"ref_item_hash_list".to_owned(),
|
||||
process_public_enc_key.enc_vec_string(self.ref_item_hash_list.clone()),
|
||||
);
|
||||
enc_attribute_list.push(ref_item_hash_list_enc);
|
||||
|
||||
let ref_pcd_hash_list_enc = PcdItemEncAttributePublic::new(
|
||||
"ref_pcd_hash_list".to_owned(),
|
||||
process_public_enc_key.enc_vec_string(self.ref_pcd_hash_list.clone()),
|
||||
);
|
||||
enc_attribute_list.push(ref_pcd_hash_list_enc);
|
||||
|
||||
let payload_list_public_enc = PcdItemEncAttributePublic::new(
|
||||
"payload_list_public".to_owned(),
|
||||
process_public_enc_key.enc_vec_string(self.payload_list_public.clone()),
|
||||
);
|
||||
enc_attribute_list.push(payload_list_public_enc);
|
||||
|
||||
let audit_code_list_public_enc = PcdItemEncAttributePublic::new(
|
||||
"audit_code_list_public".to_owned(),
|
||||
process_public_enc_key.enc_vec_string(self.audit_code_list_public.clone()),
|
||||
);
|
||||
enc_attribute_list.push(audit_code_list_public_enc);
|
||||
|
||||
enc_attribute_list
|
||||
}
|
||||
pub fn display_info(&self) {
|
||||
println!("ItemDepositPublicAttributeGroup:");
|
||||
println!("For SP Address List: {:?}", self.for_sp_address_list);
|
||||
println!("For Address List: {:?}", self.for_address_list);
|
||||
println!("Goal List: {:?}", self.goal_list);
|
||||
println!("Provider Type: {}", self.provider_type);
|
||||
println!("Ref Item Hash List: {:?}", self.ref_item_hash_list);
|
||||
println!("Ref PCD Hash List: {:?}", self.ref_pcd_hash_list);
|
||||
println!("Payload List Public: {:?}", self.payload_list_public);
|
||||
println!("Audit Code List Public: {:?}", self.audit_code_list_public);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(
|
||||
Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, FromForm,
|
||||
)]
|
||||
|
||||
pub struct ItemDepositRoleConfidentialAttributeGroup {
|
||||
pub payload_list_confidential: Vec<String>,
|
||||
pub audit_code_list_confidential: Vec<String>,
|
||||
}
|
||||
|
||||
impl ItemDepositRoleConfidentialAttributeGroup {
|
||||
pub fn new(
|
||||
payload_list_confidential: Vec<String>,
|
||||
audit_code_list_confidential: Vec<String>,
|
||||
) -> Self {
|
||||
ItemDepositRoleConfidentialAttributeGroup {
|
||||
payload_list_confidential,
|
||||
audit_code_list_confidential,
|
||||
}
|
||||
}
|
||||
pub fn enc_group(&self) -> Vec<PcdItemEncAttributeRoleConfidential> {
|
||||
let mut enc_attribute_list: Vec<PcdItemEncAttributeRoleConfidential> = Vec::new();
|
||||
|
||||
let mut payload_list_confidential_key =
|
||||
KeyEncryption::new(Some("payload_list_confidential".to_owned()), None, None);
|
||||
|
||||
if let Ok(_new) = payload_list_confidential_key.key_new_random() {
|
||||
let payload_list_confidential_enc = PcdItemEncAttributeRoleConfidential::new(
|
||||
"payload_list_confidential".to_owned(),
|
||||
payload_list_confidential_key
|
||||
.enc_vec_string(self.payload_list_confidential.clone()),
|
||||
payload_list_confidential_key,
|
||||
);
|
||||
enc_attribute_list.push(payload_list_confidential_enc);
|
||||
}
|
||||
|
||||
let mut audit_code_list_confidential_key =
|
||||
KeyEncryption::new(Some("audit_code_list_confidential".to_owned()), None, None);
|
||||
if let Ok(_new) = audit_code_list_confidential_key.key_new_random() {
|
||||
let audit_code_list_confidential_enc = PcdItemEncAttributeRoleConfidential::new(
|
||||
"audit_code_list_confidential".to_owned(),
|
||||
audit_code_list_confidential_key
|
||||
.enc_vec_string(self.audit_code_list_confidential.clone()),
|
||||
audit_code_list_confidential_key,
|
||||
);
|
||||
enc_attribute_list.push(audit_code_list_confidential_enc);
|
||||
}
|
||||
|
||||
return enc_attribute_list;
|
||||
}
|
||||
pub fn display_info(&self) {
|
||||
println!("ItemDepositRoleConfidentialAttributeGroup:");
|
||||
println!(
|
||||
"Confidential Payload List: {:?}",
|
||||
self.payload_list_confidential
|
||||
);
|
||||
println!(
|
||||
"Confidential Audit Code List: {:?}",
|
||||
self.audit_code_list_confidential
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(
|
||||
Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, FromForm,
|
||||
)]
|
||||
|
||||
pub struct ItemDepositPrivateAttributeGroup {
|
||||
pub payload_list_private: Vec<String>,
|
||||
pub audit_code_private: String,
|
||||
}
|
||||
|
||||
impl ItemDepositPrivateAttributeGroup {
|
||||
pub fn new(payload_list_private: Vec<String>, audit_code_private: String) -> Self {
|
||||
ItemDepositPrivateAttributeGroup {
|
||||
payload_list_private,
|
||||
audit_code_private,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn enc_group(&self, member_enc_key: KeyEncryption) -> Vec<PcdItemEncAttributePrivate> {
|
||||
let mut enc_attribute_list: Vec<PcdItemEncAttributePrivate> = Vec::new();
|
||||
|
||||
let payload_list_private_enc = PcdItemEncAttributePrivate::new(
|
||||
"payload_list_private".to_owned(),
|
||||
member_enc_key.enc_vec_string(self.payload_list_private.clone()),
|
||||
);
|
||||
enc_attribute_list.push(payload_list_private_enc);
|
||||
|
||||
let audit_code_private_enc = PcdItemEncAttributePrivate::new(
|
||||
"audit_code_private".to_owned(),
|
||||
member_enc_key.enc_string(self.audit_code_private.clone()),
|
||||
);
|
||||
enc_attribute_list.push(audit_code_private_enc);
|
||||
|
||||
enc_attribute_list
|
||||
}
|
||||
pub fn display_info(&self) {
|
||||
println!("ItemDepositPrivateAttributeGroup:");
|
||||
println!("Private Payload List: {:?}", self.payload_list_private);
|
||||
println!("Private Audit Code: {}", self.audit_code_private);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(
|
||||
Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, FromForm,
|
||||
)]
|
||||
|
||||
pub struct ItemDeposit {
|
||||
pub item: Item,
|
||||
pub public_attribute_group: ItemDepositPublicAttributeGroup,
|
||||
pub role_confidential_attribute_group: ItemDepositRoleConfidentialAttributeGroup,
|
||||
pub private_attribute_group: ItemDepositPrivateAttributeGroup,
|
||||
}
|
||||
|
||||
impl ItemDeposit {
|
||||
pub const ITEM_NAME: &'static str = "deposit";
|
||||
pub fn new(
|
||||
mut item: Item,
|
||||
public_attribute_group: ItemDepositPublicAttributeGroup,
|
||||
role_confidential_attribute_group: ItemDepositRoleConfidentialAttributeGroup,
|
||||
private_attribute_group: ItemDepositPrivateAttributeGroup,
|
||||
) -> Self {
|
||||
item.name = Self::ITEM_NAME.to_string();
|
||||
ItemDeposit {
|
||||
item,
|
||||
public_attribute_group,
|
||||
role_confidential_attribute_group,
|
||||
private_attribute_group,
|
||||
}
|
||||
}
|
||||
pub fn enc(
|
||||
&self,
|
||||
process_public_enc_key: KeyEncryption,
|
||||
member_private_enc_key: KeyEncryption,
|
||||
) -> PcdItemGenericEnc {
|
||||
let enc_metadata_contract_public = self
|
||||
.public_attribute_group
|
||||
.enc_group(process_public_enc_key.clone());
|
||||
|
||||
let enc_role_confidential_attribute_group =
|
||||
self.role_confidential_attribute_group.enc_group();
|
||||
|
||||
let enc_metadata_private = self
|
||||
.private_attribute_group
|
||||
.enc_group(member_private_enc_key.clone());
|
||||
|
||||
PcdItemGenericEnc::new(
|
||||
self.item
|
||||
.enc(process_public_enc_key, member_private_enc_key),
|
||||
Some(enc_metadata_contract_public),
|
||||
Some(enc_role_confidential_attribute_group),
|
||||
Some(enc_metadata_private),
|
||||
)
|
||||
}
|
||||
pub fn display_info(&self) {
|
||||
println!("ItemDeposit:");
|
||||
println!("Item:");
|
||||
self.item.display_info(); // Affiche les informations de l'objet `item`
|
||||
|
||||
println!("Public Attribute Group:");
|
||||
self.public_attribute_group.display_info(); // Affiche les informations du groupe d'attributs publics
|
||||
|
||||
println!("Role Confidential Attribute Group:");
|
||||
self.role_confidential_attribute_group.display_info(); // Affiche les informations du groupe d'attributs confidentiels
|
||||
|
||||
println!("Private Attribute Group:");
|
||||
self.private_attribute_group.display_info(); // Affiche les informations du groupe d'attributs privés
|
||||
}
|
||||
}
|
18
src/models/item_enum.rs
Normal file
18
src/models/item_enum.rs
Normal file
@ -0,0 +1,18 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::{
|
||||
item_artefact::ItemArtefact, item_commitment::ItemCommitment, item_deposit::ItemDeposit,
|
||||
item_member::ItemMember, item_payment::ItemPayment, item_peer::ItemPeer,
|
||||
item_process::ItemProcess,
|
||||
};
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||
pub enum ItemEnum {
|
||||
Process(ItemProcess),
|
||||
Peer(ItemPeer),
|
||||
Member(ItemMember),
|
||||
Payment(ItemPayment),
|
||||
Deposit(ItemDeposit),
|
||||
Artefact(ItemArtefact),
|
||||
Commitment(ItemCommitment),
|
||||
}
|
383
src/models/item_member.rs
Normal file
383
src/models/item_member.rs
Normal file
@ -0,0 +1,383 @@
|
||||
use rocket::FromForm;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::{
|
||||
item::Item, key_encryption::KeyEncryption,
|
||||
pcd_item_enc_attribute_private::PcdItemEncAttributePrivate,
|
||||
pcd_item_enc_attribute_public::PcdItemEncAttributePublic,
|
||||
pcd_item_enc_attribute_role_confidential::PcdItemEncAttributeRoleConfidential,
|
||||
pcd_item_generic_enc::PcdItemGenericEnc,
|
||||
};
|
||||
#[derive(
|
||||
Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, FromForm,
|
||||
)]
|
||||
|
||||
pub struct ItemMemberPublicAttributeGroup {
|
||||
pub sp_address_public: String,
|
||||
pub sp_address_public_sig: String,
|
||||
pub sp_address_revoke_public: String,
|
||||
pub sp_address_revoke_public_sig: String,
|
||||
pub third_sp_address_list_public: Vec<String>,
|
||||
pub data_size_max: i64,
|
||||
pub payment_method_list_public: Vec<String>,
|
||||
pub succession_process_hash: String,
|
||||
}
|
||||
|
||||
impl ItemMemberPublicAttributeGroup {
|
||||
pub fn new(
|
||||
sp_address_public: String,
|
||||
sp_address_public_sig: String,
|
||||
sp_address_revoke_public: String,
|
||||
sp_address_revoke_public_sig: String,
|
||||
third_sp_address_list_public: Vec<String>,
|
||||
data_size_max: i64,
|
||||
payment_method_list_public: Vec<String>,
|
||||
succession_process_hash: String,
|
||||
) -> Self {
|
||||
ItemMemberPublicAttributeGroup {
|
||||
sp_address_public,
|
||||
sp_address_public_sig,
|
||||
sp_address_revoke_public,
|
||||
sp_address_revoke_public_sig,
|
||||
third_sp_address_list_public,
|
||||
data_size_max,
|
||||
payment_method_list_public,
|
||||
succession_process_hash,
|
||||
}
|
||||
}
|
||||
pub fn enc_group(
|
||||
&self,
|
||||
process_public_enc_key: KeyEncryption,
|
||||
) -> Vec<PcdItemEncAttributePublic> {
|
||||
let mut enc_attribute_list: Vec<PcdItemEncAttributePublic> = Vec::new();
|
||||
|
||||
let sp_address_public_enc = PcdItemEncAttributePublic::new(
|
||||
"sp_address_public".to_owned(),
|
||||
process_public_enc_key.enc_string(self.sp_address_public.clone()),
|
||||
);
|
||||
enc_attribute_list.push(sp_address_public_enc);
|
||||
|
||||
let sp_address_public_sig_enc = PcdItemEncAttributePublic::new(
|
||||
"sp_address_public_sig".to_owned(),
|
||||
process_public_enc_key.enc_string(self.sp_address_public_sig.clone()),
|
||||
);
|
||||
enc_attribute_list.push(sp_address_public_sig_enc);
|
||||
|
||||
let sp_address_revoke_public_enc = PcdItemEncAttributePublic::new(
|
||||
"sp_address_revoke_public".to_owned(),
|
||||
process_public_enc_key.enc_string(self.sp_address_revoke_public.clone()),
|
||||
);
|
||||
enc_attribute_list.push(sp_address_revoke_public_enc);
|
||||
|
||||
let sp_address_revoke_public_sig_enc = PcdItemEncAttributePublic::new(
|
||||
"sp_address_revoke_public_sig".to_owned(),
|
||||
process_public_enc_key.enc_string(self.sp_address_revoke_public_sig.clone()),
|
||||
);
|
||||
enc_attribute_list.push(sp_address_revoke_public_sig_enc);
|
||||
|
||||
let third_sp_address_list_public_enc = PcdItemEncAttributePublic::new(
|
||||
"third_sp_address_list_public".to_owned(),
|
||||
process_public_enc_key.enc_vec_string(self.third_sp_address_list_public.clone()),
|
||||
);
|
||||
enc_attribute_list.push(third_sp_address_list_public_enc);
|
||||
|
||||
let data_size_max_enc = PcdItemEncAttributePublic::new(
|
||||
"data_size_max".to_owned(),
|
||||
process_public_enc_key.enc_i64(self.data_size_max),
|
||||
);
|
||||
enc_attribute_list.push(data_size_max_enc);
|
||||
|
||||
let payment_method_list_public_enc = PcdItemEncAttributePublic::new(
|
||||
"payment_method_list_public".to_owned(),
|
||||
process_public_enc_key.enc_vec_string(self.payment_method_list_public.clone()),
|
||||
);
|
||||
enc_attribute_list.push(payment_method_list_public_enc);
|
||||
|
||||
let succession_process_hash_enc = PcdItemEncAttributePublic::new(
|
||||
"succession_process_hash".to_owned(),
|
||||
process_public_enc_key.enc_string(self.succession_process_hash.clone()),
|
||||
);
|
||||
enc_attribute_list.push(succession_process_hash_enc);
|
||||
|
||||
enc_attribute_list
|
||||
}
|
||||
pub fn display_info(&self) {
|
||||
println!("ItemMemberPublicAttributeGroup:");
|
||||
println!("SP Address Public: {}", self.sp_address_public);
|
||||
println!(
|
||||
"SP Address Public Signature: {}",
|
||||
self.sp_address_public_sig
|
||||
);
|
||||
println!(
|
||||
"SP Address Revoke Public: {}",
|
||||
self.sp_address_revoke_public
|
||||
);
|
||||
println!(
|
||||
"SP Address Revoke Public Signature: {}",
|
||||
self.sp_address_revoke_public_sig
|
||||
);
|
||||
println!(
|
||||
"Third SP Address List Public: {:?}",
|
||||
self.third_sp_address_list_public
|
||||
);
|
||||
println!("Data Size Max: {}", self.data_size_max);
|
||||
println!(
|
||||
"Payment Method List Public: {:?}",
|
||||
self.payment_method_list_public
|
||||
);
|
||||
println!("Succession Process Hash: {}", self.succession_process_hash);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(
|
||||
Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, FromForm,
|
||||
)]
|
||||
|
||||
pub struct ItemMemberRoleConfidentialAttributeGroup {
|
||||
pub payment_method_list_confidential: Vec<String>,
|
||||
pub id_shard_info: String,
|
||||
}
|
||||
|
||||
impl ItemMemberRoleConfidentialAttributeGroup {
|
||||
pub fn new(payment_method_list_confidential: Vec<String>, id_shard_info: String) -> Self {
|
||||
ItemMemberRoleConfidentialAttributeGroup {
|
||||
payment_method_list_confidential,
|
||||
id_shard_info,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn enc_group(&self) -> Vec<PcdItemEncAttributeRoleConfidential> {
|
||||
let mut enc_attribute_list: Vec<PcdItemEncAttributeRoleConfidential> = Vec::new();
|
||||
|
||||
let mut enc_payment_method_list_confidential_key = KeyEncryption::new(
|
||||
Some("payment_method_list_confidential".to_owned()),
|
||||
None,
|
||||
None,
|
||||
);
|
||||
if let Ok(_new) = enc_payment_method_list_confidential_key.key_new_random() {
|
||||
let payment_method_list_confidential_enc = PcdItemEncAttributeRoleConfidential::new(
|
||||
"payment_method_list_confidential".to_owned(),
|
||||
enc_payment_method_list_confidential_key
|
||||
.enc_vec_string(self.payment_method_list_confidential.clone()),
|
||||
enc_payment_method_list_confidential_key,
|
||||
);
|
||||
enc_attribute_list.push(payment_method_list_confidential_enc);
|
||||
}
|
||||
|
||||
let mut enc_id_shard_info_key =
|
||||
KeyEncryption::new(Some("id_shard_info".to_owned()), None, None);
|
||||
|
||||
if let Ok(_new) = enc_id_shard_info_key.key_new_random() {
|
||||
let id_shard_info_enc = PcdItemEncAttributeRoleConfidential::new(
|
||||
"id_shard_info".to_owned(),
|
||||
enc_id_shard_info_key.enc_string(self.id_shard_info.clone()),
|
||||
enc_id_shard_info_key,
|
||||
);
|
||||
enc_attribute_list.push(id_shard_info_enc);
|
||||
}
|
||||
|
||||
return enc_attribute_list;
|
||||
}
|
||||
pub fn display_info(&self) {
|
||||
println!("ItemMemberRoleConfidentialAttributeGroup:");
|
||||
println!(
|
||||
"Confidential Payment Method List: {:?}",
|
||||
self.payment_method_list_confidential
|
||||
);
|
||||
println!("ID Shard Info: {}", self.id_shard_info);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(
|
||||
Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, FromForm,
|
||||
)]
|
||||
|
||||
pub struct ItemMemberPrivateAttributeGroup {
|
||||
pub payment_method_list_private: Vec<String>,
|
||||
pub pcd_list: Vec<String>, // Assuming this is a list of strings
|
||||
pub prd_list_list: Vec<String>,
|
||||
pub prd_update_list: Vec<String>,
|
||||
pub prd_response_list: Vec<String>,
|
||||
pub prd_message_list: Vec<String>,
|
||||
pub prd_confirm_list: Vec<String>,
|
||||
pub prd_key_backup_list: Vec<String>,
|
||||
pub prd_key_hello_list: Vec<String>,
|
||||
pub tx_sp_list: Vec<String>,
|
||||
}
|
||||
|
||||
impl ItemMemberPrivateAttributeGroup {
|
||||
pub fn new(
|
||||
payment_method_list_private: Vec<String>,
|
||||
pcd_list: Vec<String>,
|
||||
prd_list_list: Vec<String>,
|
||||
prd_update_list: Vec<String>,
|
||||
prd_response_list: Vec<String>,
|
||||
prd_message_list: Vec<String>,
|
||||
prd_confirm_list: Vec<String>,
|
||||
prd_key_backup_list: Vec<String>,
|
||||
prd_key_hello_list: Vec<String>,
|
||||
tx_sp_list: Vec<String>,
|
||||
) -> Self {
|
||||
ItemMemberPrivateAttributeGroup {
|
||||
payment_method_list_private,
|
||||
pcd_list,
|
||||
prd_list_list,
|
||||
prd_update_list,
|
||||
prd_response_list,
|
||||
prd_message_list,
|
||||
prd_confirm_list,
|
||||
prd_key_backup_list,
|
||||
prd_key_hello_list,
|
||||
tx_sp_list,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn enc_group(&self, member_enc_key: KeyEncryption) -> Vec<PcdItemEncAttributePrivate> {
|
||||
let mut enc_attribute_list: Vec<PcdItemEncAttributePrivate> = Vec::new();
|
||||
|
||||
let payment_method_list_private_enc = PcdItemEncAttributePrivate::new(
|
||||
"payment_method_list_private".to_owned(),
|
||||
member_enc_key.enc_vec_string(self.payment_method_list_private.clone()),
|
||||
);
|
||||
enc_attribute_list.push(payment_method_list_private_enc);
|
||||
|
||||
let pcd_list_enc = PcdItemEncAttributePrivate::new(
|
||||
"pcd_list".to_owned(),
|
||||
member_enc_key.enc_vec_string(self.pcd_list.clone()),
|
||||
);
|
||||
enc_attribute_list.push(pcd_list_enc);
|
||||
|
||||
let prd_list_list_enc = PcdItemEncAttributePrivate::new(
|
||||
"prd_list_list".to_owned(),
|
||||
member_enc_key.enc_vec_string(self.prd_list_list.clone()),
|
||||
);
|
||||
enc_attribute_list.push(prd_list_list_enc);
|
||||
|
||||
let prd_update_list_enc = PcdItemEncAttributePrivate::new(
|
||||
"prd_update_list".to_owned(),
|
||||
member_enc_key.enc_vec_string(self.prd_update_list.clone()),
|
||||
);
|
||||
enc_attribute_list.push(prd_update_list_enc);
|
||||
|
||||
let prd_response_list_enc = PcdItemEncAttributePrivate::new(
|
||||
"prd_response_list".to_owned(),
|
||||
member_enc_key.enc_vec_string(self.prd_response_list.clone()),
|
||||
);
|
||||
enc_attribute_list.push(prd_response_list_enc);
|
||||
|
||||
let prd_message_list_enc = PcdItemEncAttributePrivate::new(
|
||||
"prd_message_list".to_owned(),
|
||||
member_enc_key.enc_vec_string(self.prd_message_list.clone()),
|
||||
);
|
||||
enc_attribute_list.push(prd_message_list_enc);
|
||||
|
||||
let prd_confirm_list_enc = PcdItemEncAttributePrivate::new(
|
||||
"prd_confirm_list".to_owned(),
|
||||
member_enc_key.enc_vec_string(self.prd_confirm_list.clone()),
|
||||
);
|
||||
enc_attribute_list.push(prd_confirm_list_enc);
|
||||
|
||||
let prd_key_backup_list_enc = PcdItemEncAttributePrivate::new(
|
||||
"prd_key_backup_list".to_owned(),
|
||||
member_enc_key.enc_vec_string(self.prd_key_backup_list.clone()),
|
||||
);
|
||||
enc_attribute_list.push(prd_key_backup_list_enc);
|
||||
|
||||
let prd_key_hello_list_enc = PcdItemEncAttributePrivate::new(
|
||||
"prd_key_hello_list".to_owned(),
|
||||
member_enc_key.enc_vec_string(self.prd_key_hello_list.clone()),
|
||||
);
|
||||
enc_attribute_list.push(prd_key_hello_list_enc);
|
||||
|
||||
let tx_sp_list_enc = PcdItemEncAttributePrivate::new(
|
||||
"tx_sp_list".to_owned(),
|
||||
member_enc_key.enc_vec_string(self.tx_sp_list.clone()),
|
||||
);
|
||||
enc_attribute_list.push(tx_sp_list_enc);
|
||||
|
||||
enc_attribute_list
|
||||
}
|
||||
pub fn display_info(&self) {
|
||||
println!("ItemMemberPrivateAttributeGroup:");
|
||||
println!(
|
||||
"Private Payment Method List: {:?}",
|
||||
self.payment_method_list_private
|
||||
);
|
||||
println!("PCD List: {:?}", self.pcd_list);
|
||||
println!("PRD List List: {:?}", self.prd_list_list);
|
||||
println!("PRD Update List: {:?}", self.prd_update_list);
|
||||
println!("PRD Response List: {:?}", self.prd_response_list);
|
||||
println!("PRD Message List: {:?}", self.prd_message_list);
|
||||
println!("PRD Confirm List: {:?}", self.prd_confirm_list);
|
||||
println!("PRD Key Backup List: {:?}", self.prd_key_backup_list);
|
||||
println!("PRD Key Hello List: {:?}", self.prd_key_hello_list);
|
||||
println!("TX SP List: {:?}", self.tx_sp_list);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(
|
||||
Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, FromForm,
|
||||
)]
|
||||
|
||||
pub struct ItemMember {
|
||||
pub item: Item,
|
||||
pub public_attribute_group: ItemMemberPublicAttributeGroup,
|
||||
pub role_confidential_attribute_group: ItemMemberRoleConfidentialAttributeGroup,
|
||||
pub private_attribute_group: ItemMemberPrivateAttributeGroup,
|
||||
}
|
||||
|
||||
impl ItemMember {
|
||||
pub const ITEM_NAME: &'static str = "member";
|
||||
pub fn new(
|
||||
mut item: Item,
|
||||
public_attribute_group: ItemMemberPublicAttributeGroup,
|
||||
role_confidential_attribute_group: ItemMemberRoleConfidentialAttributeGroup,
|
||||
private_attribute_group: ItemMemberPrivateAttributeGroup,
|
||||
) -> Self {
|
||||
item.name = Self::ITEM_NAME.to_string();
|
||||
ItemMember {
|
||||
item,
|
||||
public_attribute_group,
|
||||
role_confidential_attribute_group,
|
||||
private_attribute_group,
|
||||
}
|
||||
}
|
||||
pub fn enc(
|
||||
&self,
|
||||
process_public_enc_key: KeyEncryption,
|
||||
member_private_enc_key: KeyEncryption,
|
||||
) -> PcdItemGenericEnc {
|
||||
let enc_metadata_contract_public = self
|
||||
.public_attribute_group
|
||||
.enc_group(process_public_enc_key.clone());
|
||||
|
||||
let enc_role_confidential_attribute_group =
|
||||
self.role_confidential_attribute_group.enc_group();
|
||||
|
||||
let enc_metadata_private = self
|
||||
.private_attribute_group
|
||||
.enc_group(member_private_enc_key.clone());
|
||||
|
||||
PcdItemGenericEnc::new(
|
||||
self.item
|
||||
.enc(process_public_enc_key, member_private_enc_key),
|
||||
Some(enc_metadata_contract_public),
|
||||
Some(enc_role_confidential_attribute_group),
|
||||
Some(enc_metadata_private),
|
||||
)
|
||||
}
|
||||
pub fn display_info(&self) {
|
||||
println!("ItemMember:");
|
||||
println!("Item:");
|
||||
self.item.display_info(); // Affiche les informations de l'objet `item`
|
||||
|
||||
println!("Member Public Attribute Group:");
|
||||
self.public_attribute_group.display_info(); // Affiche les informations du groupe d'attributs publics
|
||||
|
||||
println!("Member Role Confidential Attribute Group:");
|
||||
self.role_confidential_attribute_group.display_info(); // Affiche les informations du groupe d'attributs confidentiels
|
||||
|
||||
println!("Member Private Attribute Group:");
|
||||
self.private_attribute_group.display_info(); // Affiche les informations du groupe d'attributs privés
|
||||
}
|
||||
}
|
324
src/models/item_payment.rs
Normal file
324
src/models/item_payment.rs
Normal file
@ -0,0 +1,324 @@
|
||||
use rocket::FromForm;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::{
|
||||
item::Item, key_encryption::KeyEncryption,
|
||||
pcd_item_enc_attribute_private::PcdItemEncAttributePrivate,
|
||||
pcd_item_enc_attribute_public::PcdItemEncAttributePublic,
|
||||
pcd_item_enc_attribute_role_confidential::PcdItemEncAttributeRoleConfidential,
|
||||
pcd_item_generic_enc::PcdItemGenericEnc,
|
||||
};
|
||||
#[derive(
|
||||
Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, FromForm,
|
||||
)]
|
||||
|
||||
pub struct ItemPaymentPublicAttributeGroup {
|
||||
pub for_sp_address_list: Vec<String>,
|
||||
pub goal_list: Vec<String>,
|
||||
pub provider_type: String,
|
||||
pub commitment_pcd_hash_list: Vec<String>,
|
||||
pub order_pcd_hash_list: Vec<String>,
|
||||
pub invoice_pcd_hash_list: Vec<String>,
|
||||
pub pay_pcd_hash_list: Vec<String>,
|
||||
pub ref_item_hash_list: Vec<String>,
|
||||
pub ref_pcd_hash_list: Vec<String>,
|
||||
pub payload_list_public: Vec<String>,
|
||||
pub audit_code_list_public: Vec<String>,
|
||||
}
|
||||
|
||||
impl ItemPaymentPublicAttributeGroup {
|
||||
pub fn new(
|
||||
for_sp_address_list: Vec<String>,
|
||||
goal_list: Vec<String>,
|
||||
provider_type: String,
|
||||
commitment_pcd_hash_list: Vec<String>,
|
||||
order_pcd_hash_list: Vec<String>,
|
||||
invoice_pcd_hash_list: Vec<String>,
|
||||
pay_pcd_hash_list: Vec<String>,
|
||||
ref_item_hash_list: Vec<String>,
|
||||
ref_pcd_hash_list: Vec<String>,
|
||||
payload_list_public: Vec<String>,
|
||||
audit_code_list_public: Vec<String>,
|
||||
) -> Self {
|
||||
ItemPaymentPublicAttributeGroup {
|
||||
for_sp_address_list,
|
||||
goal_list,
|
||||
provider_type,
|
||||
commitment_pcd_hash_list,
|
||||
order_pcd_hash_list,
|
||||
invoice_pcd_hash_list,
|
||||
pay_pcd_hash_list,
|
||||
ref_item_hash_list,
|
||||
ref_pcd_hash_list,
|
||||
payload_list_public,
|
||||
audit_code_list_public,
|
||||
}
|
||||
}
|
||||
pub fn enc_group(
|
||||
&self,
|
||||
process_public_enc_key: KeyEncryption,
|
||||
) -> Vec<PcdItemEncAttributePublic> {
|
||||
let mut enc_attribute_list: Vec<PcdItemEncAttributePublic> = Vec::new();
|
||||
|
||||
let for_sp_address_list_enc = PcdItemEncAttributePublic::new(
|
||||
"for_sp_address_list".to_owned(),
|
||||
process_public_enc_key.enc_vec_string(self.for_sp_address_list.clone()),
|
||||
);
|
||||
enc_attribute_list.push(for_sp_address_list_enc);
|
||||
|
||||
let goal_list_enc = PcdItemEncAttributePublic::new(
|
||||
"goal_list".to_owned(),
|
||||
process_public_enc_key.enc_vec_string(self.goal_list.clone()),
|
||||
);
|
||||
enc_attribute_list.push(goal_list_enc);
|
||||
|
||||
let provider_type_enc = PcdItemEncAttributePublic::new(
|
||||
"provider_type".to_owned(),
|
||||
process_public_enc_key.enc_string(self.provider_type.clone()),
|
||||
);
|
||||
enc_attribute_list.push(provider_type_enc);
|
||||
|
||||
let commitment_pcd_hash_list_enc = PcdItemEncAttributePublic::new(
|
||||
"commitment_pcd_hash_list".to_owned(),
|
||||
process_public_enc_key.enc_vec_string(self.commitment_pcd_hash_list.clone()),
|
||||
);
|
||||
enc_attribute_list.push(commitment_pcd_hash_list_enc);
|
||||
|
||||
let order_pcd_hash_list_enc = PcdItemEncAttributePublic::new(
|
||||
"order_pcd_hash_list".to_owned(),
|
||||
process_public_enc_key.enc_vec_string(self.order_pcd_hash_list.clone()),
|
||||
);
|
||||
enc_attribute_list.push(order_pcd_hash_list_enc);
|
||||
|
||||
let invoice_pcd_hash_list_enc = PcdItemEncAttributePublic::new(
|
||||
"invoice_pcd_hash_list".to_owned(),
|
||||
process_public_enc_key.enc_vec_string(self.invoice_pcd_hash_list.clone()),
|
||||
);
|
||||
enc_attribute_list.push(invoice_pcd_hash_list_enc);
|
||||
|
||||
let pay_pcd_hash_list_enc = PcdItemEncAttributePublic::new(
|
||||
"pay_pcd_hash_list".to_owned(),
|
||||
process_public_enc_key.enc_vec_string(self.pay_pcd_hash_list.clone()),
|
||||
);
|
||||
enc_attribute_list.push(pay_pcd_hash_list_enc);
|
||||
|
||||
let ref_item_hash_list_enc = PcdItemEncAttributePublic::new(
|
||||
"ref_item_hash_list".to_owned(),
|
||||
process_public_enc_key.enc_vec_string(self.ref_item_hash_list.clone()),
|
||||
);
|
||||
enc_attribute_list.push(ref_item_hash_list_enc);
|
||||
|
||||
let ref_pcd_hash_list_enc = PcdItemEncAttributePublic::new(
|
||||
"ref_pcd_hash_list".to_owned(),
|
||||
process_public_enc_key.enc_vec_string(self.ref_pcd_hash_list.clone()),
|
||||
);
|
||||
enc_attribute_list.push(ref_pcd_hash_list_enc);
|
||||
|
||||
let payload_list_public_enc = PcdItemEncAttributePublic::new(
|
||||
"payload_list_public".to_owned(),
|
||||
process_public_enc_key.enc_vec_string(self.payload_list_public.clone()),
|
||||
);
|
||||
enc_attribute_list.push(payload_list_public_enc);
|
||||
|
||||
let audit_code_list_public_enc = PcdItemEncAttributePublic::new(
|
||||
"audit_code_list_public".to_owned(),
|
||||
process_public_enc_key.enc_vec_string(self.audit_code_list_public.clone()),
|
||||
);
|
||||
enc_attribute_list.push(audit_code_list_public_enc);
|
||||
|
||||
enc_attribute_list
|
||||
}
|
||||
pub fn display_info(&self) {
|
||||
println!("ItemPaymentPublicAttributeGroup:");
|
||||
println!("For SP Address List: {:?}", self.for_sp_address_list);
|
||||
println!("Goal List: {:?}", self.goal_list);
|
||||
println!("Provider Type: {}", self.provider_type);
|
||||
println!(
|
||||
"Commitment PCD Hash List: {:?}",
|
||||
self.commitment_pcd_hash_list
|
||||
);
|
||||
println!("Order PCD Hash List: {:?}", self.order_pcd_hash_list);
|
||||
println!("Invoice PCD Hash List: {:?}", self.invoice_pcd_hash_list);
|
||||
println!("Pay PCD Hash List: {:?}", self.pay_pcd_hash_list);
|
||||
println!("Ref Item Hash List: {:?}", self.ref_item_hash_list);
|
||||
println!("Ref PCD Hash List: {:?}", self.ref_pcd_hash_list);
|
||||
println!("Payload List Public: {:?}", self.payload_list_public);
|
||||
println!("Audit Code List Public: {:?}", self.audit_code_list_public);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(
|
||||
Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, FromForm,
|
||||
)]
|
||||
|
||||
pub struct ItemPaymentRoleConfidentialAttributeGroup {
|
||||
pub payload_list_confidential: Vec<String>,
|
||||
pub audit_code_list_confidential: Vec<String>,
|
||||
}
|
||||
|
||||
impl ItemPaymentRoleConfidentialAttributeGroup {
|
||||
pub fn new(
|
||||
payload_list_confidential: Vec<String>,
|
||||
audit_code_list_confidential: Vec<String>,
|
||||
) -> Self {
|
||||
ItemPaymentRoleConfidentialAttributeGroup {
|
||||
payload_list_confidential,
|
||||
audit_code_list_confidential,
|
||||
}
|
||||
}
|
||||
pub fn display_info(&self) {
|
||||
println!("ItemPaymentRoleConfidentialAttributeGroup:");
|
||||
println!(
|
||||
"Confidential Payload List: {:?}",
|
||||
self.payload_list_confidential
|
||||
);
|
||||
println!(
|
||||
"Confidential Audit Code List: {:?}",
|
||||
self.audit_code_list_confidential
|
||||
);
|
||||
}
|
||||
|
||||
pub fn enc_group(&self) -> Vec<PcdItemEncAttributeRoleConfidential> {
|
||||
let mut enc_attribute_list: Vec<PcdItemEncAttributeRoleConfidential> = Vec::new();
|
||||
|
||||
// tag_list
|
||||
let mut enc_payload_list_confidential =
|
||||
KeyEncryption::new(Some("payload_list_confidential".to_owned()), None, None);
|
||||
if let Ok(_new) = enc_payload_list_confidential.key_new_random() {
|
||||
let enc_attribute_payload_list_confidential = PcdItemEncAttributeRoleConfidential::new(
|
||||
"payload_list_confidential".to_owned(),
|
||||
enc_payload_list_confidential
|
||||
.enc_vec_string(self.payload_list_confidential.clone()),
|
||||
enc_payload_list_confidential,
|
||||
);
|
||||
enc_attribute_list.push(enc_attribute_payload_list_confidential);
|
||||
}
|
||||
|
||||
// zone_listaudit_code_list_confidential
|
||||
let mut enc_attribute_audit_code_list_confidential_key =
|
||||
KeyEncryption::new(Some("zone_list".to_owned()), None, None);
|
||||
if let Ok(_new) = enc_attribute_audit_code_list_confidential_key.key_new_random() {
|
||||
let enc_attribute_audit_code_list_confidential =
|
||||
PcdItemEncAttributeRoleConfidential::new(
|
||||
"zone_list".to_owned(),
|
||||
enc_attribute_audit_code_list_confidential_key
|
||||
.enc_vec_string(self.audit_code_list_confidential.clone()),
|
||||
enc_attribute_audit_code_list_confidential_key,
|
||||
);
|
||||
enc_attribute_list.push(enc_attribute_audit_code_list_confidential);
|
||||
}
|
||||
|
||||
return enc_attribute_list;
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(
|
||||
Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, FromForm,
|
||||
)]
|
||||
|
||||
pub struct ItemPaymentPrivateAttributeGroup {
|
||||
pub payload_list_private: Vec<String>,
|
||||
pub audit_code_private: String,
|
||||
}
|
||||
|
||||
impl ItemPaymentPrivateAttributeGroup {
|
||||
pub fn new(payload_list_private: Vec<String>, audit_code_private: String) -> Self {
|
||||
ItemPaymentPrivateAttributeGroup {
|
||||
payload_list_private,
|
||||
audit_code_private,
|
||||
}
|
||||
}
|
||||
pub fn display_info(&self) {
|
||||
println!("ItemPaymentRoleConfidentialAttributeGroup:");
|
||||
println!("Confidential Payload List: {:?}", self.payload_list_private);
|
||||
println!(
|
||||
"Confidential Audit Code List: {:?}",
|
||||
self.audit_code_private
|
||||
);
|
||||
}
|
||||
|
||||
pub fn enc_group(&self, member_enc_key: KeyEncryption) -> Vec<PcdItemEncAttributePrivate> {
|
||||
let mut enc_attribute_list: Vec<PcdItemEncAttributePrivate> = Vec::new();
|
||||
|
||||
let payload_list_private_enc = PcdItemEncAttributePrivate::new(
|
||||
"payload_list".to_owned(),
|
||||
member_enc_key.enc_vec_string(self.payload_list_private.clone()),
|
||||
);
|
||||
enc_attribute_list.push(payload_list_private_enc);
|
||||
|
||||
let audit_code_private_enc = PcdItemEncAttributePrivate::new(
|
||||
"audit_code_private".to_owned(),
|
||||
member_enc_key.enc_string(self.audit_code_private.clone()),
|
||||
);
|
||||
enc_attribute_list.push(audit_code_private_enc);
|
||||
|
||||
enc_attribute_list
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(
|
||||
Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, FromForm,
|
||||
)]
|
||||
|
||||
pub struct ItemPayment {
|
||||
pub item: Item,
|
||||
pub public_attribute_group: ItemPaymentPublicAttributeGroup,
|
||||
pub role_confidential_attribute_group: ItemPaymentRoleConfidentialAttributeGroup,
|
||||
pub private_attribute_group: ItemPaymentPrivateAttributeGroup,
|
||||
}
|
||||
|
||||
impl ItemPayment {
|
||||
pub const ITEM_NAME: &'static str = "payment";
|
||||
pub fn new(
|
||||
mut item: Item,
|
||||
public_attribute_group: ItemPaymentPublicAttributeGroup,
|
||||
role_confidential_attribute_group: ItemPaymentRoleConfidentialAttributeGroup,
|
||||
private_attribute_group: ItemPaymentPrivateAttributeGroup,
|
||||
) -> Self {
|
||||
item.name = Self::ITEM_NAME.to_string();
|
||||
ItemPayment {
|
||||
item,
|
||||
public_attribute_group,
|
||||
role_confidential_attribute_group,
|
||||
private_attribute_group,
|
||||
}
|
||||
}
|
||||
pub fn enc(
|
||||
&self,
|
||||
process_public_enc_key: KeyEncryption,
|
||||
member_private_enc_key: KeyEncryption,
|
||||
) -> PcdItemGenericEnc {
|
||||
let enc_metadata_contract_public = self
|
||||
.public_attribute_group
|
||||
.enc_group(process_public_enc_key.clone());
|
||||
|
||||
let enc_role_confidential_attribute_group =
|
||||
self.role_confidential_attribute_group.enc_group();
|
||||
|
||||
let enc_metadata_private = self
|
||||
.private_attribute_group
|
||||
.enc_group(member_private_enc_key.clone());
|
||||
|
||||
PcdItemGenericEnc::new(
|
||||
self.item
|
||||
.enc(process_public_enc_key, member_private_enc_key),
|
||||
Some(enc_metadata_contract_public),
|
||||
Some(enc_role_confidential_attribute_group),
|
||||
Some(enc_metadata_private),
|
||||
)
|
||||
}
|
||||
pub fn display_info(&self) {
|
||||
println!("ItemPayment:");
|
||||
println!("Item:");
|
||||
self.item.display_info(); // Affiche les informations de l'objet `item`
|
||||
|
||||
println!("Public Attribute Group:");
|
||||
self.public_attribute_group.display_info(); // Affiche les informations du groupe d'attributs publics
|
||||
|
||||
println!("Role Confidential Attribute Group:");
|
||||
self.role_confidential_attribute_group.display_info(); // Affiche les informations du groupe d'attributs confidentiels
|
||||
|
||||
println!("Private Attribute Group:");
|
||||
self.private_attribute_group.display_info(); // Affiche les informations du groupe d'attributs privés
|
||||
}
|
||||
}
|
240
src/models/item_peer.rs
Normal file
240
src/models/item_peer.rs
Normal file
@ -0,0 +1,240 @@
|
||||
use rocket::FromForm;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::{
|
||||
item::Item, key_encryption::KeyEncryption,
|
||||
pcd_item_enc_attribute_private::PcdItemEncAttributePrivate,
|
||||
pcd_item_enc_attribute_public::PcdItemEncAttributePublic,
|
||||
pcd_item_generic_enc::PcdItemGenericEnc,
|
||||
};
|
||||
#[derive(
|
||||
Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, FromForm,
|
||||
)]
|
||||
|
||||
pub struct ItemPeerPublicAttributeGroup {
|
||||
pub sp_address: String,
|
||||
pub domain: String,
|
||||
pub ip_address: String,
|
||||
pub pow_difficulty: u32,
|
||||
pub pow_pattern: String,
|
||||
pub pow_prefix: String,
|
||||
pub data_size_max: i64,
|
||||
pub timestamp_delay_max: u64,
|
||||
pub daily_hash_list: Vec<String>,
|
||||
pub daily_sp_tx_mine_list: Vec<String>,
|
||||
pub daily_sp_tx_mine_reward_list: Vec<String>,
|
||||
}
|
||||
|
||||
impl ItemPeerPublicAttributeGroup {
|
||||
pub fn new(
|
||||
sp_address: String,
|
||||
domain: String,
|
||||
ip_address: String,
|
||||
pow_difficulty: u32,
|
||||
pow_pattern: String,
|
||||
pow_prefix: String,
|
||||
data_size_max: i64,
|
||||
timestamp_delay_max: u64,
|
||||
daily_hash_list: Vec<String>,
|
||||
daily_sp_tx_mine_list: Vec<String>,
|
||||
daily_sp_tx_mine_reward_list: Vec<String>,
|
||||
) -> Self {
|
||||
ItemPeerPublicAttributeGroup {
|
||||
sp_address,
|
||||
domain,
|
||||
ip_address,
|
||||
pow_difficulty,
|
||||
pow_pattern,
|
||||
pow_prefix,
|
||||
data_size_max,
|
||||
timestamp_delay_max,
|
||||
daily_hash_list,
|
||||
daily_sp_tx_mine_list,
|
||||
daily_sp_tx_mine_reward_list,
|
||||
}
|
||||
}
|
||||
pub fn enc_group(
|
||||
&self,
|
||||
process_public_enc_key: KeyEncryption,
|
||||
) -> Vec<PcdItemEncAttributePublic> {
|
||||
let mut enc_attribute_list: Vec<PcdItemEncAttributePublic> = Vec::new();
|
||||
|
||||
let sp_address_enc = PcdItemEncAttributePublic::new(
|
||||
"sp_address".to_owned(),
|
||||
process_public_enc_key.enc_string(self.sp_address.clone()),
|
||||
);
|
||||
enc_attribute_list.push(sp_address_enc);
|
||||
|
||||
let domain_enc = PcdItemEncAttributePublic::new(
|
||||
"domain".to_owned(),
|
||||
process_public_enc_key.enc_string(self.domain.clone()),
|
||||
);
|
||||
enc_attribute_list.push(domain_enc);
|
||||
|
||||
let ip_address_enc = PcdItemEncAttributePublic::new(
|
||||
"ip_address".to_owned(),
|
||||
process_public_enc_key.enc_string(self.ip_address.clone()),
|
||||
);
|
||||
enc_attribute_list.push(ip_address_enc);
|
||||
|
||||
let pow_difficulty_enc = PcdItemEncAttributePublic::new(
|
||||
"pow_difficulty".to_owned(),
|
||||
process_public_enc_key.enc_u32(self.pow_difficulty),
|
||||
);
|
||||
enc_attribute_list.push(pow_difficulty_enc);
|
||||
|
||||
let pow_pattern_enc = PcdItemEncAttributePublic::new(
|
||||
"pow_pattern".to_owned(),
|
||||
process_public_enc_key.enc_string(self.pow_pattern.clone()),
|
||||
);
|
||||
enc_attribute_list.push(pow_pattern_enc);
|
||||
|
||||
let pow_prefix_enc = PcdItemEncAttributePublic::new(
|
||||
"pow_prefix".to_owned(),
|
||||
process_public_enc_key.enc_string(self.pow_prefix.clone()),
|
||||
);
|
||||
enc_attribute_list.push(pow_prefix_enc);
|
||||
|
||||
let data_size_max_enc = PcdItemEncAttributePublic::new(
|
||||
"data_size_max".to_owned(),
|
||||
process_public_enc_key.enc_i64(self.data_size_max),
|
||||
);
|
||||
enc_attribute_list.push(data_size_max_enc);
|
||||
|
||||
let timestamp_delay_max_enc = PcdItemEncAttributePublic::new(
|
||||
"timestamp_delay_max".to_owned(),
|
||||
process_public_enc_key.enc_u64(self.timestamp_delay_max),
|
||||
);
|
||||
enc_attribute_list.push(timestamp_delay_max_enc);
|
||||
|
||||
let daily_hash_list_enc = PcdItemEncAttributePublic::new(
|
||||
"daily_hash_list".to_owned(),
|
||||
process_public_enc_key.enc_vec_string(self.daily_hash_list.clone()),
|
||||
);
|
||||
enc_attribute_list.push(daily_hash_list_enc);
|
||||
|
||||
let daily_sp_tx_mine_list_enc = PcdItemEncAttributePublic::new(
|
||||
"daily_sp_tx_mine_list".to_owned(),
|
||||
process_public_enc_key.enc_vec_string(self.daily_sp_tx_mine_list.clone()),
|
||||
);
|
||||
enc_attribute_list.push(daily_sp_tx_mine_list_enc);
|
||||
|
||||
let daily_sp_tx_mine_reward_list_enc = PcdItemEncAttributePublic::new(
|
||||
"daily_sp_tx_mine_reward_list".to_owned(),
|
||||
process_public_enc_key.enc_vec_string(self.daily_sp_tx_mine_reward_list.clone()),
|
||||
);
|
||||
enc_attribute_list.push(daily_sp_tx_mine_reward_list_enc);
|
||||
|
||||
enc_attribute_list
|
||||
}
|
||||
pub fn display_info(&self) {
|
||||
println!("ItemPeerPublicAttributeGroup:");
|
||||
println!("SP Address: {}", self.sp_address);
|
||||
println!("Domain: {}", self.domain);
|
||||
println!("IP Address: {}", self.ip_address);
|
||||
println!("PoW Difficulty: {}", self.pow_difficulty);
|
||||
println!("PoW Pattern: {}", self.pow_pattern);
|
||||
println!("PoW Prefix: {}", self.pow_prefix);
|
||||
println!("Data Size Max: {}", self.data_size_max);
|
||||
println!("Timestamp Delay Max: {}", self.timestamp_delay_max);
|
||||
println!("Daily Hash List: {:?}", self.daily_hash_list);
|
||||
println!("Daily SP Tx Mine List: {:?}", self.daily_sp_tx_mine_list);
|
||||
println!(
|
||||
"Daily SP Tx Mine Reward List: {:?}",
|
||||
self.daily_sp_tx_mine_reward_list
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(
|
||||
Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, FromForm,
|
||||
)]
|
||||
|
||||
pub struct ItemPeerPrivateAttributeGroup {
|
||||
pub config: String, // Assuming it's a simple string for now
|
||||
}
|
||||
|
||||
impl ItemPeerPrivateAttributeGroup {
|
||||
pub fn new(config: String) -> Self {
|
||||
ItemPeerPrivateAttributeGroup { config }
|
||||
}
|
||||
pub fn display_info(&self) {
|
||||
println!("ItemPeerPrivateAttributeGroup:");
|
||||
println!("Config: {}", self.config);
|
||||
}
|
||||
|
||||
pub fn enc_group(&self, member_enc_key: KeyEncryption) -> Vec<PcdItemEncAttributePrivate> {
|
||||
let mut enc_attribute_list: Vec<PcdItemEncAttributePrivate> = Vec::new();
|
||||
|
||||
let config_enc = PcdItemEncAttributePrivate::new(
|
||||
"config".to_owned(),
|
||||
member_enc_key.enc_string(self.config.clone()),
|
||||
);
|
||||
enc_attribute_list.push(config_enc);
|
||||
|
||||
enc_attribute_list
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(
|
||||
Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, FromForm,
|
||||
)]
|
||||
|
||||
pub struct ItemPeer {
|
||||
pub item: Item,
|
||||
pub layer_list: Vec<String>,
|
||||
pub public_attribute_group: ItemPeerPublicAttributeGroup,
|
||||
pub private_attribute_group: ItemPeerPrivateAttributeGroup,
|
||||
}
|
||||
|
||||
impl ItemPeer {
|
||||
pub const ITEM_NAME: &'static str = "peer";
|
||||
pub fn new(
|
||||
mut item: Item,
|
||||
layer_list: Vec<String>,
|
||||
public_attribute_group: ItemPeerPublicAttributeGroup,
|
||||
private_attribute_group: ItemPeerPrivateAttributeGroup,
|
||||
) -> Self {
|
||||
item.name = Self::ITEM_NAME.to_string();
|
||||
ItemPeer {
|
||||
item,
|
||||
layer_list,
|
||||
public_attribute_group,
|
||||
private_attribute_group,
|
||||
}
|
||||
}
|
||||
pub fn enc(
|
||||
&self,
|
||||
process_public_enc_key: KeyEncryption,
|
||||
member_private_enc_key: KeyEncryption,
|
||||
) -> PcdItemGenericEnc {
|
||||
let enc_metadata_contract_public = self
|
||||
.public_attribute_group
|
||||
.enc_group(process_public_enc_key.clone());
|
||||
|
||||
let enc_metadata_private = self
|
||||
.private_attribute_group
|
||||
.enc_group(member_private_enc_key.clone());
|
||||
|
||||
PcdItemGenericEnc::new(
|
||||
self.item
|
||||
.enc(process_public_enc_key, member_private_enc_key),
|
||||
Some(enc_metadata_contract_public),
|
||||
None,
|
||||
Some(enc_metadata_private),
|
||||
)
|
||||
}
|
||||
pub fn display_info(&self) {
|
||||
println!("ItemPeer:");
|
||||
println!("Item:");
|
||||
self.item.display_info(); // Affiche les informations de l'objet `item`
|
||||
|
||||
println!("Layer List: {:?}", self.layer_list);
|
||||
|
||||
println!("Peer Public Attribute Group:");
|
||||
self.public_attribute_group.display_info(); // Affiche les informations du groupe d'attributs publics
|
||||
|
||||
println!("Peer Private Attribute Group:");
|
||||
self.private_attribute_group.display_info(); // Affiche les informations du groupe d'attributs privés
|
||||
}
|
||||
}
|
91
src/models/item_process.rs
Normal file
91
src/models/item_process.rs
Normal file
@ -0,0 +1,91 @@
|
||||
use rocket::FromForm;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::{
|
||||
item::Item, key_encryption::KeyEncryption,
|
||||
pcd_item_enc_attribute_public::PcdItemEncAttributePublic,
|
||||
pcd_item_generic_enc::PcdItemGenericEnc, roles_group::RolesGroup,
|
||||
};
|
||||
|
||||
#[derive(
|
||||
Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, FromForm,
|
||||
)]
|
||||
|
||||
pub struct ItemProcessPublicAttributeGroup {
|
||||
// Fields for public attributes
|
||||
// Example field
|
||||
pub roles_group: RolesGroup,
|
||||
}
|
||||
|
||||
impl ItemProcessPublicAttributeGroup {
|
||||
pub fn new(roles_group: RolesGroup) -> Self {
|
||||
ItemProcessPublicAttributeGroup { roles_group }
|
||||
}
|
||||
pub fn display_info(&self) {
|
||||
println!("ItemProcessPublicAttributeGroup:");
|
||||
println!("Roles Group:");
|
||||
self.roles_group.display_info(); // Display information for `roles_group`
|
||||
}
|
||||
pub fn enc_group(
|
||||
&self,
|
||||
process_public_enc_key: KeyEncryption,
|
||||
) -> Vec<PcdItemEncAttributePublic> {
|
||||
let mut enc_attribute_list: Vec<PcdItemEncAttributePublic> = Vec::new();
|
||||
let roles_group_enc = PcdItemEncAttributePublic::new(
|
||||
"roles_group".to_owned(),
|
||||
process_public_enc_key.enc_roles_group(self.roles_group.clone()),
|
||||
);
|
||||
enc_attribute_list.push(roles_group_enc);
|
||||
enc_attribute_list
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(
|
||||
Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, FromForm,
|
||||
)]
|
||||
|
||||
pub struct ItemProcess {
|
||||
pub item: Item,
|
||||
pub item_process_public_attribute_group: ItemProcessPublicAttributeGroup,
|
||||
}
|
||||
|
||||
impl ItemProcess {
|
||||
pub const ITEM_NAME: &'static str = "process";
|
||||
pub fn new(
|
||||
mut item: Item,
|
||||
item_process_public_attribute_group: ItemProcessPublicAttributeGroup,
|
||||
) -> Self {
|
||||
item.name = Self::ITEM_NAME.to_string();
|
||||
ItemProcess {
|
||||
item,
|
||||
item_process_public_attribute_group,
|
||||
}
|
||||
}
|
||||
pub fn display_info(&self) {
|
||||
println!("ItemProcess:");
|
||||
println!("Item:");
|
||||
self.item.display_info(); // Display information for `item`
|
||||
|
||||
println!("Process Public Attribute Group:");
|
||||
self.item_process_public_attribute_group.display_info(); // Display information for `item_process_public_attribute_group`
|
||||
}
|
||||
pub fn enc(
|
||||
&self,
|
||||
process_public_enc_key: KeyEncryption,
|
||||
member_private_enc_key: KeyEncryption,
|
||||
) -> PcdItemGenericEnc {
|
||||
let enc_metadata_contract_public = self
|
||||
.item_process_public_attribute_group
|
||||
.enc_group(process_public_enc_key.clone());
|
||||
|
||||
PcdItemGenericEnc::new(
|
||||
self.item
|
||||
.enc(process_public_enc_key, member_private_enc_key),
|
||||
Some(enc_metadata_contract_public),
|
||||
None,
|
||||
None,
|
||||
)
|
||||
}
|
||||
|
||||
// Additional methods for ItemProcess can be added here
|
||||
}
|
250
src/models/key_encryption.rs
Normal file
250
src/models/key_encryption.rs
Normal file
@ -0,0 +1,250 @@
|
||||
use rand::RngCore;
|
||||
use rocket::FromForm;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::{json, Value};
|
||||
|
||||
use core::result::Result as CoreResult;
|
||||
|
||||
use super::metadata::Amount;
|
||||
use super::metadata::Number;
|
||||
use super::request_pcd::RequestPcd;
|
||||
use super::request_prd_confirm::RequestPrdConfirm;
|
||||
use super::request_prd_key_backup::RequestPrdKeyBackup;
|
||||
use super::request_prd_key_hello::RequestPrdKeyHello;
|
||||
use super::request_prd_list::RequestPrdList;
|
||||
use super::request_prd_message::RequestPrdMessage;
|
||||
use super::request_prd_response::RequestPrdResponse;
|
||||
use super::request_prd_update::RequestPrdUpdate;
|
||||
use super::roles_group::RolesGroup;
|
||||
|
||||
use aes::cipher::consts::U32;
|
||||
use aes::cipher::generic_array::GenericArray;
|
||||
use aes_gcm::{
|
||||
aead::{AeadInPlace, KeyInit},
|
||||
Aes256Gcm,
|
||||
};
|
||||
use rand::rngs::OsRng;
|
||||
|
||||
pub struct Aes256GcmIv96Bit {
|
||||
pub key: GenericArray<u8, U32>,
|
||||
}
|
||||
|
||||
impl Aes256GcmIv96Bit {
|
||||
pub fn new() -> Self {
|
||||
let mut key_bytes = [0u8; 32];
|
||||
OsRng.fill_bytes(&mut key_bytes);
|
||||
let key = GenericArray::from_slice(&key_bytes);
|
||||
Aes256GcmIv96Bit { key: key.clone() }
|
||||
}
|
||||
|
||||
pub fn encrypt(&self, data: &[u8]) -> CoreResult<Vec<u8>, aes_gcm::Error> {
|
||||
let cipher = Aes256Gcm::new(&self.key);
|
||||
let mut nonce = [0u8; 12];
|
||||
OsRng.fill_bytes(&mut nonce);
|
||||
|
||||
let mut buffer = data.to_vec();
|
||||
cipher.encrypt_in_place(GenericArray::from_slice(&nonce), b"", &mut buffer)?;
|
||||
|
||||
Ok([nonce.to_vec(), buffer].concat())
|
||||
}
|
||||
|
||||
pub fn decrypt(&self, data: &[u8]) -> CoreResult<Vec<u8>, aes_gcm::Error> {
|
||||
if data.len() < 12 {
|
||||
return Err(aes_gcm::Error); // Remplacer par une erreur appropriée
|
||||
}
|
||||
|
||||
let (nonce, encrypted_data) = data.split_at(12);
|
||||
let mut buffer = encrypted_data.to_vec();
|
||||
let cipher = Aes256Gcm::new(&self.key);
|
||||
cipher.decrypt_in_place(GenericArray::from_slice(nonce), b"", &mut buffer)?;
|
||||
|
||||
Ok(buffer)
|
||||
}
|
||||
pub fn encrypt_string(&self, data: &str) -> CoreResult<String, String> {
|
||||
match self.encrypt(data.as_bytes()) {
|
||||
Ok(encrypted_data) => Ok(base64::encode(encrypted_data)),
|
||||
Err(_) => Err("Erreur de chiffrement".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decrypt_string(&self, data: &str) -> CoreResult<String, String> {
|
||||
let decoded_data = match base64::decode(data) {
|
||||
Ok(data) => data,
|
||||
Err(_) => return Err("Erreur de décodage Base64".to_string()),
|
||||
};
|
||||
|
||||
match self.decrypt(&decoded_data) {
|
||||
Ok(decrypted_data) => match String::from_utf8(decrypted_data) {
|
||||
Ok(text) => Ok(text),
|
||||
Err(_) => Err("Erreur de conversion UTF-8".to_string()),
|
||||
},
|
||||
Err(_) => Err("Erreur de déchiffrement".to_string()),
|
||||
}
|
||||
}
|
||||
pub fn export_key(&self) -> String {
|
||||
base64::encode(&self.key)
|
||||
}
|
||||
|
||||
pub fn import_key(encoded_key: &str) -> CoreResult<Self, String> {
|
||||
match base64::decode(encoded_key) {
|
||||
Ok(decoded_key) => {
|
||||
if decoded_key.len() == 32 {
|
||||
let key = GenericArray::from_slice(&decoded_key);
|
||||
Ok(Aes256GcmIv96Bit { key: key.clone() })
|
||||
} else {
|
||||
Err("La taille de la clé n'est pas valide".to_string())
|
||||
}
|
||||
}
|
||||
Err(_) => Err("Échec du décodage de la clé".to_string()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(
|
||||
Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, FromForm,
|
||||
)]
|
||||
pub struct KeyEncryption {
|
||||
pub attribute_name: Option<String>,
|
||||
pub key: Option<String>,
|
||||
pub algorithm: Option<String>,
|
||||
}
|
||||
|
||||
impl KeyEncryption {
|
||||
pub fn new(
|
||||
attribute_name: Option<String>,
|
||||
key: Option<String>,
|
||||
algorithm: Option<String>,
|
||||
) -> Self {
|
||||
KeyEncryption {
|
||||
attribute_name,
|
||||
key,
|
||||
algorithm,
|
||||
}
|
||||
}
|
||||
pub fn key_new_random(&mut self) -> CoreResult<String, String> {
|
||||
let new_key = Aes256GcmIv96Bit::new().export_key();
|
||||
self.key = Some(new_key.clone());
|
||||
Ok(new_key)
|
||||
}
|
||||
pub fn encode(&self, data: String) -> CoreResult<String, String> {
|
||||
if let Some(ref key) = self.key {
|
||||
let decoded_key = Aes256GcmIv96Bit::import_key(key)?;
|
||||
let encrypted_data = decoded_key.encrypt_string(&data)?;
|
||||
Ok(encrypted_data)
|
||||
} else {
|
||||
Err("Aucune clé n'est définie".to_string())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode(&self, encrypted_data: String) -> CoreResult<String, String> {
|
||||
if let Some(ref key) = self.key {
|
||||
let decoded_key = Aes256GcmIv96Bit::import_key(key)?;
|
||||
let decrypted_data = decoded_key.decrypt_string(&encrypted_data)?;
|
||||
Ok(decrypted_data)
|
||||
} else {
|
||||
Err("Aucune clé n'est définie".to_string())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn display_info(&self) {
|
||||
println!("KeyEncryption:");
|
||||
println!("Attribute Name: {:?}", self.attribute_name);
|
||||
println!("Key: {:?}", self.key);
|
||||
println!("Algorithm: {:?}", self.algorithm);
|
||||
}
|
||||
pub fn enc(&self, data: Value) -> String {
|
||||
let data_string = serde_json::to_string(&data).unwrap_or_else(|_| "".to_string());
|
||||
self.encode(data_string).unwrap_or_else(|_| "".to_string())
|
||||
}
|
||||
pub fn enc_string(&self, data: String) -> String {
|
||||
self.enc(Value::String(data))
|
||||
}
|
||||
pub fn enc_i64(&self, data: i64) -> String {
|
||||
self.enc(Value::Number(data.into()))
|
||||
}
|
||||
pub fn enc_u64(&self, data: u64) -> String {
|
||||
self.enc(Value::Number(data.into()))
|
||||
}
|
||||
pub fn enc_u32(&self, data: u32) -> String {
|
||||
self.enc(Value::Number(data.into()))
|
||||
}
|
||||
pub fn enc_vec_string(&self, list: Vec<String>) -> String {
|
||||
self.enc(Value::Array(list.into_iter().map(Value::String).collect()))
|
||||
}
|
||||
pub fn enc_vec_key_encryption(&self, list: Vec<KeyEncryption>) -> String {
|
||||
// Utilisez `serde_json::to_value` pour convertir chaque `KeyEncryption` en `Value`
|
||||
let json_list: Vec<Value> = list
|
||||
.into_iter()
|
||||
.map(|key_enc| serde_json::to_value(key_enc).unwrap_or_else(|_| json!({})))
|
||||
.collect();
|
||||
|
||||
self.enc(Value::Array(json_list))
|
||||
}
|
||||
pub fn enc_amount(&self, amount: Amount) -> String {
|
||||
let amount_value = serde_json::to_value(amount).unwrap_or_else(|_| json!({}));
|
||||
self.enc(amount_value)
|
||||
}
|
||||
pub fn enc_number(&self, number: Number) -> String {
|
||||
let number_value = serde_json::to_value(number).unwrap_or_else(|_| json!({}));
|
||||
self.enc(number_value)
|
||||
}
|
||||
pub fn enc_bool(&self, data: bool) -> String {
|
||||
self.enc(Value::Bool(data))
|
||||
}
|
||||
pub fn enc_vec_u32(&self, list: Vec<u32>) -> String {
|
||||
let number_list: Vec<Value> = list
|
||||
.into_iter()
|
||||
.map(|num| Value::Number(serde_json::Number::from(num)))
|
||||
.collect();
|
||||
|
||||
self.enc(Value::Array(number_list))
|
||||
}
|
||||
|
||||
pub fn enc_vec_i64(&self, list: Vec<i64>) -> String {
|
||||
let number_list: Vec<Value> = list
|
||||
.into_iter()
|
||||
.map(|num| Value::Number(serde_json::Number::from(num)))
|
||||
.collect();
|
||||
|
||||
self.enc(Value::Array(number_list))
|
||||
}
|
||||
pub fn enc_vec_bool(&self, list: Vec<bool>) -> String {
|
||||
self.enc(Value::Array(list.into_iter().map(Value::Bool).collect()))
|
||||
}
|
||||
pub fn enc_pcd(&self, pcd: RequestPcd) -> String {
|
||||
let pcd_value = serde_json::to_value(pcd).unwrap_or_else(|_| json!({}));
|
||||
self.enc(pcd_value)
|
||||
}
|
||||
pub fn enc_prd_update(&self, prd: RequestPrdUpdate) -> String {
|
||||
let prd_value = serde_json::to_value(prd).unwrap_or_else(|_| json!({}));
|
||||
self.enc(prd_value)
|
||||
}
|
||||
pub fn enc_prd_list(&self, pcd: RequestPrdList) -> String {
|
||||
let prd_value = serde_json::to_value(pcd).unwrap_or_else(|_| json!({}));
|
||||
self.enc(prd_value)
|
||||
}
|
||||
pub fn enc_prd_response(&self, prd: RequestPrdResponse) -> String {
|
||||
let prd_value = serde_json::to_value(prd).unwrap_or_else(|_| json!({}));
|
||||
self.enc(prd_value)
|
||||
}
|
||||
pub fn enc_prd_confirm(&self, prd: RequestPrdConfirm) -> String {
|
||||
let prd_value = serde_json::to_value(prd).unwrap_or_else(|_| json!({}));
|
||||
self.enc(prd_value)
|
||||
}
|
||||
pub fn enc_prd_message(&self, prd: RequestPrdMessage) -> String {
|
||||
let prd_value = serde_json::to_value(prd).unwrap_or_else(|_| json!({}));
|
||||
self.enc(prd_value)
|
||||
}
|
||||
pub fn enc_prd_key_backup(&self, prd: RequestPrdKeyBackup) -> String {
|
||||
let prd_value = serde_json::to_value(prd).unwrap_or_else(|_| json!({}));
|
||||
self.enc(prd_value)
|
||||
}
|
||||
pub fn enc_prd_key_hello(&self, prd: RequestPrdKeyHello) -> String {
|
||||
let prd_value = serde_json::to_value(prd).unwrap_or_else(|_| json!({}));
|
||||
self.enc(prd_value)
|
||||
}
|
||||
pub fn enc_roles_group(&self, roles: RolesGroup) -> String {
|
||||
let roles_value = serde_json::to_value(roles).unwrap_or_else(|_| json!({}));
|
||||
self.enc(roles_value)
|
||||
}
|
||||
}
|
113
src/models/message.rs
Normal file
113
src/models/message.rs
Normal file
@ -0,0 +1,113 @@
|
||||
use chrono::Utc;
|
||||
|
||||
use rocket::FromForm;
|
||||
use sha2::{Digest, Sha256};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::shared_peer::SharedPeer;
|
||||
use super::shared_process::SharedProcess;
|
||||
#[derive(
|
||||
Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, FromForm,
|
||||
)]
|
||||
|
||||
pub struct Pow {
|
||||
pub data_hash: String,
|
||||
timestamp: Option<u64>,
|
||||
pub nonce: Option<u64>,
|
||||
pub pathern: String,
|
||||
pub difficulty: usize,
|
||||
}
|
||||
|
||||
impl Pow {
|
||||
pub fn new(data_hash: String, pathern: String, difficulty: usize) -> Self {
|
||||
let mut pow = Pow {
|
||||
data_hash,
|
||||
nonce: None,
|
||||
timestamp: None,
|
||||
pathern,
|
||||
difficulty,
|
||||
};
|
||||
pow.find();
|
||||
return pow;
|
||||
}
|
||||
pub fn display_info(&self) {
|
||||
println!("Pow:");
|
||||
println!("Data Hash: {}", self.data_hash);
|
||||
println!("Timestamp: {}", self.timestamp.as_ref().unwrap_or(&0));
|
||||
println!("Nonce: {}", self.nonce.as_ref().unwrap_or(&0));
|
||||
println!("Pathern: {}", self.pathern);
|
||||
println!("Difficulty: {}", self.difficulty);
|
||||
}
|
||||
pub fn find(&mut self) {
|
||||
let mut nonce: u64 = 0;
|
||||
loop {
|
||||
// Mise à jour du timestamp à chaque itération
|
||||
let current_timestamp = Utc::now().timestamp() as u64;
|
||||
self.timestamp = Some(current_timestamp);
|
||||
|
||||
// Créer une chaîne avec le hash actuel, le timestamp et le nonce
|
||||
let data: String = format!("{}{}{}", self.data_hash, current_timestamp, nonce);
|
||||
|
||||
// Calculer le hash SHA-256
|
||||
let mut hasher = Sha256::new();
|
||||
hasher.update(data);
|
||||
let result = hasher.finalize();
|
||||
let hash_str: String = format!("{:x}", result);
|
||||
|
||||
// Vérifier si le hash correspond au motif de difficulté
|
||||
if hash_str.starts_with(&"0".repeat(self.difficulty as usize)) {
|
||||
self.nonce = Some(nonce);
|
||||
break;
|
||||
}
|
||||
|
||||
nonce += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(
|
||||
Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, FromForm,
|
||||
)]
|
||||
|
||||
pub struct Message {
|
||||
pub shared_peer_list: Vec<SharedPeer>,
|
||||
pub shared_process_list: Vec<SharedProcess>,
|
||||
pub faucet_sp_address: String,
|
||||
pub pow: Pow, // Assuming Pow is a predefined struct
|
||||
}
|
||||
|
||||
impl Message {
|
||||
pub fn new(
|
||||
shared_peer_list: Vec<SharedPeer>,
|
||||
shared_process_list: Vec<SharedProcess>,
|
||||
faucet_sp_address: String,
|
||||
pow_data_hash: String,
|
||||
pow_pathern: String,
|
||||
pow_difficulty: usize,
|
||||
) -> Self {
|
||||
let pow: Pow = Pow::new(pow_data_hash, pow_pathern, pow_difficulty);
|
||||
Message {
|
||||
shared_peer_list,
|
||||
shared_process_list,
|
||||
faucet_sp_address,
|
||||
pow,
|
||||
}
|
||||
}
|
||||
pub fn display_info(&self) {
|
||||
println!("Message:");
|
||||
println!("Shared Peer List:");
|
||||
for shared_peer in &self.shared_peer_list {
|
||||
shared_peer.display_info(); // Assuming SharedPeers has a display_info method
|
||||
}
|
||||
|
||||
println!("Shared Process List:");
|
||||
for shared_process in &self.shared_process_list {
|
||||
shared_process.display_info(); // Assuming SharedProcess has a display_info method
|
||||
}
|
||||
|
||||
println!("Faucet SP Address: {}", self.faucet_sp_address);
|
||||
println!("PoW:");
|
||||
self.pow.display_info(); // Assuming Pow has a display_info method
|
||||
}
|
||||
}
|
54
src/models/message_client.rs
Normal file
54
src/models/message_client.rs
Normal file
@ -0,0 +1,54 @@
|
||||
use super::{message::Message, shared_peer::SharedPeer, shared_process::SharedProcess};
|
||||
|
||||
use rocket::FromForm;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(
|
||||
Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, FromForm,
|
||||
)]
|
||||
|
||||
pub struct MessageClient {
|
||||
pub message: Message, // Assuming Message is a predefined struct
|
||||
pub request_enc: String,
|
||||
pub request_hash: String,
|
||||
}
|
||||
|
||||
impl MessageClient {
|
||||
pub fn new(
|
||||
request_enc: String,
|
||||
request_hash: String,
|
||||
message_shared_peer_list: Vec<SharedPeer>,
|
||||
message_shared_process_list: Vec<SharedProcess>,
|
||||
message_faucet_sp_address: String,
|
||||
pow_pathern: String,
|
||||
pow_difficulty: usize,
|
||||
) -> Self {
|
||||
let pow_data_hash = request_hash;
|
||||
let message: Message = Message::new(
|
||||
message_shared_peer_list,
|
||||
message_shared_process_list,
|
||||
message_faucet_sp_address,
|
||||
pow_data_hash.clone(),
|
||||
pow_pathern,
|
||||
pow_difficulty,
|
||||
);
|
||||
MessageClient {
|
||||
message,
|
||||
request_enc,
|
||||
request_hash: pow_data_hash,
|
||||
}
|
||||
}
|
||||
pub fn send(&self) {
|
||||
for shared_peer in &self.message.shared_peer_list {
|
||||
shared_peer.send_message_client(self.clone()); // Assuming SharedPeers has a send method
|
||||
}
|
||||
}
|
||||
pub fn display_info(&self) {
|
||||
println!("MessageClient:");
|
||||
println!("Message:");
|
||||
self.message.display_info(); // Assuming Message has a display_info method
|
||||
println!("Message Hash: {}", self.request_hash);
|
||||
|
||||
println!("Request Enc: {}", self.request_enc);
|
||||
}
|
||||
}
|
22
src/models/message_connect.rs
Normal file
22
src/models/message_connect.rs
Normal file
@ -0,0 +1,22 @@
|
||||
use rocket::FromForm;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::message::Message;
|
||||
#[derive(
|
||||
Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, FromForm,
|
||||
)]
|
||||
|
||||
pub struct MessageConnect {
|
||||
pub message: Message, // Assuming Message is a predefined struct
|
||||
}
|
||||
|
||||
impl MessageConnect {
|
||||
pub fn new(message: Message) -> Self {
|
||||
MessageConnect { message }
|
||||
}
|
||||
pub fn display_info(&self) {
|
||||
println!("MessageConnect:");
|
||||
println!("Message:");
|
||||
self.message.display_info(); // Assuming Message has a display_info method
|
||||
}
|
||||
}
|
152
src/models/metadata.rs
Normal file
152
src/models/metadata.rs
Normal file
@ -0,0 +1,152 @@
|
||||
use rocket::FromForm;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::key_encryption::KeyEncryption;
|
||||
#[derive(
|
||||
Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, FromForm,
|
||||
)]
|
||||
|
||||
pub struct Number {
|
||||
pub fixed_state: bool,
|
||||
pub number: i32,
|
||||
pub number_unit: String,
|
||||
}
|
||||
|
||||
impl Number {
|
||||
// Constructor for Number struct
|
||||
pub fn new(fixed_state: bool, number: i32, number_unit: String) -> Self {
|
||||
Number {
|
||||
fixed_state,
|
||||
number,
|
||||
number_unit,
|
||||
}
|
||||
}
|
||||
pub fn display_info(&self) {
|
||||
println!("Number:");
|
||||
println!("Fixed State: {}", self.fixed_state);
|
||||
println!("Number: {}", self.number);
|
||||
println!("Number Unit: {}", self.number_unit);
|
||||
}
|
||||
|
||||
// Additional methods for Number can be added here.
|
||||
}
|
||||
|
||||
// Struct for representing an amount with various attributes.
|
||||
#[derive(
|
||||
Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, FromForm,
|
||||
)]
|
||||
|
||||
pub struct Amount {
|
||||
pub timestamp: u64,
|
||||
pub change_source_list: Vec<String>,
|
||||
pub amount_cent: i64,
|
||||
pub amount_unit: String,
|
||||
pub amount_unit_ref: String, // This can be a reference to an external unit system.
|
||||
}
|
||||
|
||||
impl Amount {
|
||||
// Constructor for Amount struct
|
||||
pub fn new(
|
||||
timestamp: u64,
|
||||
change_source_list: Vec<String>,
|
||||
amount_cent: i64,
|
||||
amount_unit: String,
|
||||
amount_unit_ref: String,
|
||||
) -> Self {
|
||||
Amount {
|
||||
timestamp,
|
||||
change_source_list,
|
||||
amount_cent,
|
||||
amount_unit,
|
||||
amount_unit_ref,
|
||||
}
|
||||
}
|
||||
pub fn display(&self) -> String {
|
||||
format!(
|
||||
"Amount: {} {} {} {} {}",
|
||||
self.timestamp,
|
||||
self.change_source_list.join(","),
|
||||
self.amount_cent,
|
||||
self.amount_unit,
|
||||
self.amount_unit_ref
|
||||
)
|
||||
}
|
||||
pub fn display_info(&self) {
|
||||
println!("Amount:");
|
||||
println!("Timestamp: {}", self.timestamp);
|
||||
println!("Change Source List: {:?}", self.change_source_list);
|
||||
println!("Amount cent: {}", self.amount_cent);
|
||||
println!("Amount Unit: {}", self.amount_unit);
|
||||
println!("Amount Unit Reference: {}", self.amount_unit_ref);
|
||||
}
|
||||
// Additional methods for Amount can be added here.
|
||||
}
|
||||
|
||||
#[derive(
|
||||
Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, FromForm,
|
||||
)]
|
||||
|
||||
pub struct MetaData {
|
||||
pub tag_list: Vec<String>,
|
||||
pub zone_list: Vec<String>,
|
||||
pub label_list: Vec<String>,
|
||||
pub ref_list: Vec<String>,
|
||||
pub data_list: Vec<String>,
|
||||
pub amount: Amount,
|
||||
pub number: Number,
|
||||
pub render_template_list: Vec<String>,
|
||||
pub legal_text_list: Vec<String>,
|
||||
pub key_list: Vec<KeyEncryption>,
|
||||
}
|
||||
|
||||
impl MetaData {
|
||||
pub fn new(
|
||||
tag_list: Vec<String>,
|
||||
zone_list: Vec<String>,
|
||||
label_list: Vec<String>,
|
||||
ref_list: Vec<String>,
|
||||
data_list: Vec<String>,
|
||||
amount: Amount,
|
||||
number: Number,
|
||||
render_template_list: Vec<String>,
|
||||
legal_text_list: Vec<String>,
|
||||
key_list: Vec<KeyEncryption>,
|
||||
) -> Self {
|
||||
MetaData {
|
||||
tag_list,
|
||||
zone_list,
|
||||
label_list,
|
||||
ref_list,
|
||||
data_list,
|
||||
amount,
|
||||
number,
|
||||
render_template_list,
|
||||
legal_text_list,
|
||||
key_list,
|
||||
}
|
||||
}
|
||||
pub fn display_info(&self) {
|
||||
println!("MetaData:");
|
||||
println!("Tag List: {:?}", self.tag_list);
|
||||
println!("Zone List: {:?}", self.zone_list);
|
||||
println!("Label List: {:?}", self.label_list);
|
||||
println!("Ref List: {:?}", self.ref_list);
|
||||
println!("Data List: {:?}", self.data_list);
|
||||
|
||||
println!("Amount:");
|
||||
self.amount.display_info(); // Assuming Amount has a display_info method
|
||||
|
||||
println!("Number:");
|
||||
self.number.display_info(); // Assuming Number has a display_info method
|
||||
|
||||
println!("Render Template List: {:?}", self.render_template_list);
|
||||
println!("Legal Text List: {:?}", self.legal_text_list);
|
||||
|
||||
println!("Key List:");
|
||||
for key in &self.key_list {
|
||||
key.display_info(); // Assuming KeyEncryption has a display_info method
|
||||
}
|
||||
}
|
||||
|
||||
// Methods for manipulating MetaData can be added here.
|
||||
}
|
146
src/models/metadata_contract_public.rs
Normal file
146
src/models/metadata_contract_public.rs
Normal file
@ -0,0 +1,146 @@
|
||||
use rocket::FromForm;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::{
|
||||
key_encryption::KeyEncryption, metadata::MetaData,
|
||||
pcd_item_enc_attribute_public::PcdItemEncAttributePublic,
|
||||
};
|
||||
|
||||
#[derive(
|
||||
Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, FromForm,
|
||||
)]
|
||||
|
||||
pub struct MetadataContractPublic {
|
||||
pub meta_data: MetaData,
|
||||
}
|
||||
|
||||
impl MetadataContractPublic {
|
||||
pub fn new(meta_data: MetaData) -> Self {
|
||||
MetadataContractPublic { meta_data }
|
||||
}
|
||||
pub fn display_info(&self) {
|
||||
println!("MetadataContractPublic:");
|
||||
// Assuming MetaData has a display_info method
|
||||
self.meta_data.display_info(); // Display information for `meta_data`
|
||||
}
|
||||
pub fn enc_list(
|
||||
&self,
|
||||
process_public_enc_key: KeyEncryption,
|
||||
) -> Vec<PcdItemEncAttributePublic> {
|
||||
let mut enc_attribute_list: Vec<PcdItemEncAttributePublic> = Vec::new();
|
||||
|
||||
let enc_attribute_tag_list_key = KeyEncryption::new(
|
||||
Some("tag_list".to_owned()),
|
||||
process_public_enc_key.key.clone(),
|
||||
process_public_enc_key.algorithm.clone(),
|
||||
);
|
||||
let enc_attribute_tag_list = PcdItemEncAttributePublic::new(
|
||||
"tag_list".to_owned(),
|
||||
enc_attribute_tag_list_key.enc_vec_string(self.meta_data.tag_list.clone()),
|
||||
);
|
||||
enc_attribute_list.push(enc_attribute_tag_list);
|
||||
|
||||
let enc_attribute_zone_list_key = KeyEncryption::new(
|
||||
Some("zone_list".to_owned()),
|
||||
process_public_enc_key.key.clone(),
|
||||
process_public_enc_key.algorithm.clone(),
|
||||
);
|
||||
let enc_attribute_zone_list = PcdItemEncAttributePublic::new(
|
||||
"zone_list".to_owned(),
|
||||
enc_attribute_zone_list_key.enc_vec_string(self.meta_data.zone_list.clone()),
|
||||
);
|
||||
enc_attribute_list.push(enc_attribute_zone_list);
|
||||
|
||||
let enc_attribute_label_list_key = KeyEncryption::new(
|
||||
Some("label_list".to_owned()),
|
||||
process_public_enc_key.key.clone(),
|
||||
process_public_enc_key.algorithm.clone(),
|
||||
);
|
||||
let enc_attribute_label_list = PcdItemEncAttributePublic::new(
|
||||
"label_list".to_owned(),
|
||||
enc_attribute_label_list_key.enc_vec_string(self.meta_data.label_list.clone()),
|
||||
);
|
||||
enc_attribute_list.push(enc_attribute_label_list);
|
||||
|
||||
let enc_attribute_ref_list_key = KeyEncryption::new(
|
||||
Some("ref_list".to_owned()),
|
||||
process_public_enc_key.key.clone(),
|
||||
process_public_enc_key.algorithm.clone(),
|
||||
);
|
||||
let enc_attribute_ref_list = PcdItemEncAttributePublic::new(
|
||||
"ref_list".to_owned(),
|
||||
enc_attribute_ref_list_key.enc_vec_string(self.meta_data.ref_list.clone()),
|
||||
);
|
||||
enc_attribute_list.push(enc_attribute_ref_list);
|
||||
|
||||
let enc_attribute_data_list_key = KeyEncryption::new(
|
||||
Some("data_list".to_owned()),
|
||||
process_public_enc_key.key.clone(),
|
||||
process_public_enc_key.algorithm.clone(),
|
||||
);
|
||||
let enc_attribute_data_list = PcdItemEncAttributePublic::new(
|
||||
"data_list".to_owned(),
|
||||
enc_attribute_data_list_key.enc_vec_string(self.meta_data.data_list.clone()),
|
||||
);
|
||||
enc_attribute_list.push(enc_attribute_data_list);
|
||||
|
||||
let enc_attribute_amount_key = KeyEncryption::new(
|
||||
Some("amount".to_owned()),
|
||||
process_public_enc_key.key.clone(),
|
||||
process_public_enc_key.algorithm.clone(),
|
||||
);
|
||||
let enc_attribute_amount = PcdItemEncAttributePublic::new(
|
||||
"amount".to_owned(),
|
||||
enc_attribute_amount_key.enc_amount(self.meta_data.amount.clone()),
|
||||
);
|
||||
enc_attribute_list.push(enc_attribute_amount);
|
||||
|
||||
let enc_attribute_number_key = KeyEncryption::new(
|
||||
Some("number".to_owned()),
|
||||
process_public_enc_key.key.clone(),
|
||||
process_public_enc_key.algorithm.clone(),
|
||||
);
|
||||
let enc_attribute_number = PcdItemEncAttributePublic::new(
|
||||
"number".to_owned(),
|
||||
enc_attribute_number_key.enc_number(self.meta_data.number.clone()),
|
||||
);
|
||||
enc_attribute_list.push(enc_attribute_number);
|
||||
|
||||
let enc_attribute_render_template_list_key = KeyEncryption::new(
|
||||
Some("render_template_list".to_owned()),
|
||||
process_public_enc_key.key.clone(),
|
||||
process_public_enc_key.algorithm.clone(),
|
||||
);
|
||||
let enc_attribute_render_template_list = PcdItemEncAttributePublic::new(
|
||||
"render_template_list".to_owned(),
|
||||
enc_attribute_render_template_list_key
|
||||
.enc_vec_string(self.meta_data.render_template_list.clone()),
|
||||
);
|
||||
enc_attribute_list.push(enc_attribute_render_template_list);
|
||||
|
||||
let enc_attribute_legal_text_list_key = KeyEncryption::new(
|
||||
Some("legal_text_list".to_owned()),
|
||||
process_public_enc_key.key.clone(),
|
||||
process_public_enc_key.algorithm.clone(),
|
||||
);
|
||||
let enc_attribute_legal_text_list = PcdItemEncAttributePublic::new(
|
||||
"legal_text_list".to_owned(),
|
||||
enc_attribute_legal_text_list_key
|
||||
.enc_vec_string(self.meta_data.legal_text_list.clone()),
|
||||
);
|
||||
enc_attribute_list.push(enc_attribute_legal_text_list);
|
||||
|
||||
let enc_attribute_key_list_key = KeyEncryption::new(
|
||||
Some("key_list".to_owned()),
|
||||
process_public_enc_key.key.clone(),
|
||||
process_public_enc_key.algorithm.clone(),
|
||||
);
|
||||
let enc_attribute_key_list = PcdItemEncAttributePublic::new(
|
||||
"key_list".to_owned(),
|
||||
enc_attribute_key_list_key.enc_vec_key_encryption(self.meta_data.key_list.clone()),
|
||||
);
|
||||
enc_attribute_list.push(enc_attribute_key_list);
|
||||
|
||||
return enc_attribute_list;
|
||||
}
|
||||
}
|
146
src/models/metadata_private.rs
Normal file
146
src/models/metadata_private.rs
Normal file
@ -0,0 +1,146 @@
|
||||
use rocket::FromForm;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::{
|
||||
key_encryption::KeyEncryption, metadata::MetaData,
|
||||
pcd_item_enc_attribute_private::PcdItemEncAttributePrivate,
|
||||
};
|
||||
|
||||
#[derive(
|
||||
Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, FromForm,
|
||||
)]
|
||||
|
||||
pub struct MetadataPrivate {
|
||||
pub meta_data: MetaData,
|
||||
}
|
||||
|
||||
impl MetadataPrivate {
|
||||
pub fn new(meta_data: MetaData) -> Self {
|
||||
MetadataPrivate { meta_data }
|
||||
}
|
||||
pub fn display_info(&self) {
|
||||
println!("MetadataPrivate:");
|
||||
// Assuming MetaData has a display_info method
|
||||
self.meta_data.display_info(); // Display information for `meta_data`
|
||||
}
|
||||
pub fn enc_list(
|
||||
&self,
|
||||
member_private_enc_key: KeyEncryption,
|
||||
) -> Vec<PcdItemEncAttributePrivate> {
|
||||
let mut enc_attribute_list: Vec<PcdItemEncAttributePrivate> = Vec::new();
|
||||
|
||||
let enc_attribute_tag_list_key = KeyEncryption::new(
|
||||
Some("tag_list".to_owned()),
|
||||
member_private_enc_key.key.clone(),
|
||||
member_private_enc_key.algorithm.clone(),
|
||||
);
|
||||
let enc_attribute_tag_list = PcdItemEncAttributePrivate::new(
|
||||
"tag_list".to_owned(),
|
||||
enc_attribute_tag_list_key.enc_vec_string(self.meta_data.tag_list.clone()),
|
||||
);
|
||||
enc_attribute_list.push(enc_attribute_tag_list);
|
||||
|
||||
let enc_attribute_zone_list_key = KeyEncryption::new(
|
||||
Some("zone_list".to_owned()),
|
||||
member_private_enc_key.key.clone(),
|
||||
member_private_enc_key.algorithm.clone(),
|
||||
);
|
||||
let enc_attribute_zone_list = PcdItemEncAttributePrivate::new(
|
||||
"zone_list".to_owned(),
|
||||
enc_attribute_zone_list_key.enc_vec_string(self.meta_data.zone_list.clone()),
|
||||
);
|
||||
enc_attribute_list.push(enc_attribute_zone_list);
|
||||
|
||||
let enc_attribute_label_list_key = KeyEncryption::new(
|
||||
Some("label_list".to_owned()),
|
||||
member_private_enc_key.key.clone(),
|
||||
member_private_enc_key.algorithm.clone(),
|
||||
);
|
||||
let enc_attribute_label_list = PcdItemEncAttributePrivate::new(
|
||||
"label_list".to_owned(),
|
||||
enc_attribute_label_list_key.enc_vec_string(self.meta_data.label_list.clone()),
|
||||
);
|
||||
enc_attribute_list.push(enc_attribute_label_list);
|
||||
|
||||
let enc_attribute_ref_list_key = KeyEncryption::new(
|
||||
Some("ref_list".to_owned()),
|
||||
member_private_enc_key.key.clone(),
|
||||
member_private_enc_key.algorithm.clone(),
|
||||
);
|
||||
let enc_attribute_ref_list = PcdItemEncAttributePrivate::new(
|
||||
"ref_list".to_owned(),
|
||||
enc_attribute_ref_list_key.enc_vec_string(self.meta_data.ref_list.clone()),
|
||||
);
|
||||
enc_attribute_list.push(enc_attribute_ref_list);
|
||||
|
||||
let enc_attribute_data_list_key = KeyEncryption::new(
|
||||
Some("data_list".to_owned()),
|
||||
member_private_enc_key.key.clone(),
|
||||
member_private_enc_key.algorithm.clone(),
|
||||
);
|
||||
let enc_attribute_data_list = PcdItemEncAttributePrivate::new(
|
||||
"data_list".to_owned(),
|
||||
enc_attribute_data_list_key.enc_vec_string(self.meta_data.data_list.clone()),
|
||||
);
|
||||
enc_attribute_list.push(enc_attribute_data_list);
|
||||
|
||||
let enc_attribute_amount_key = KeyEncryption::new(
|
||||
Some("amount".to_owned()),
|
||||
member_private_enc_key.key.clone(),
|
||||
member_private_enc_key.algorithm.clone(),
|
||||
);
|
||||
let enc_attribute_amount = PcdItemEncAttributePrivate::new(
|
||||
"amount".to_owned(),
|
||||
enc_attribute_amount_key.enc_amount(self.meta_data.amount.clone()),
|
||||
);
|
||||
enc_attribute_list.push(enc_attribute_amount);
|
||||
|
||||
let enc_attribute_number_key = KeyEncryption::new(
|
||||
Some("number".to_owned()),
|
||||
member_private_enc_key.key.clone(),
|
||||
member_private_enc_key.algorithm.clone(),
|
||||
);
|
||||
let enc_attribute_number = PcdItemEncAttributePrivate::new(
|
||||
"number".to_owned(),
|
||||
enc_attribute_number_key.enc_number(self.meta_data.number.clone()),
|
||||
);
|
||||
enc_attribute_list.push(enc_attribute_number);
|
||||
|
||||
let enc_attribute_render_template_list_key = KeyEncryption::new(
|
||||
Some("render_template_list".to_owned()),
|
||||
member_private_enc_key.key.clone(),
|
||||
member_private_enc_key.algorithm.clone(),
|
||||
);
|
||||
let enc_attribute_render_template_list = PcdItemEncAttributePrivate::new(
|
||||
"render_template_list".to_owned(),
|
||||
enc_attribute_render_template_list_key
|
||||
.enc_vec_string(self.meta_data.render_template_list.clone()),
|
||||
);
|
||||
enc_attribute_list.push(enc_attribute_render_template_list);
|
||||
|
||||
let enc_attribute_legal_text_list_key = KeyEncryption::new(
|
||||
Some("legal_text_list".to_owned()),
|
||||
member_private_enc_key.key.clone(),
|
||||
member_private_enc_key.algorithm.clone(),
|
||||
);
|
||||
let enc_attribute_legal_text_list = PcdItemEncAttributePrivate::new(
|
||||
"legal_text_list".to_owned(),
|
||||
enc_attribute_legal_text_list_key
|
||||
.enc_vec_string(self.meta_data.legal_text_list.clone()),
|
||||
);
|
||||
enc_attribute_list.push(enc_attribute_legal_text_list);
|
||||
|
||||
let enc_attribute_key_list_key = KeyEncryption::new(
|
||||
Some("key_list".to_owned()),
|
||||
member_private_enc_key.key.clone(),
|
||||
member_private_enc_key.algorithm.clone(),
|
||||
);
|
||||
let enc_attribute_key_list = PcdItemEncAttributePrivate::new(
|
||||
"key_list".to_owned(),
|
||||
enc_attribute_key_list_key.enc_vec_key_encryption(self.meta_data.key_list.clone()),
|
||||
);
|
||||
enc_attribute_list.push(enc_attribute_key_list);
|
||||
|
||||
return enc_attribute_list;
|
||||
}
|
||||
}
|
155
src/models/metadata_role_confidential.rs
Normal file
155
src/models/metadata_role_confidential.rs
Normal file
@ -0,0 +1,155 @@
|
||||
use rocket::FromForm;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::{
|
||||
key_encryption::KeyEncryption, metadata::MetaData,
|
||||
pcd_item_enc_attribute_role_confidential::PcdItemEncAttributeRoleConfidential,
|
||||
};
|
||||
|
||||
#[derive(
|
||||
Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, FromForm,
|
||||
)]
|
||||
|
||||
pub struct MetadataRoleConfidential {
|
||||
pub meta_data: MetaData,
|
||||
}
|
||||
|
||||
impl MetadataRoleConfidential {
|
||||
pub fn new(meta_data: MetaData) -> Self {
|
||||
MetadataRoleConfidential { meta_data }
|
||||
}
|
||||
pub fn display_info(&self) {
|
||||
println!("MetadataRoleConfidential:");
|
||||
// Assuming MetaData has a display_info method
|
||||
self.meta_data.display_info(); // Display information for `meta_data`
|
||||
}
|
||||
pub fn enc_list(&self) -> Vec<PcdItemEncAttributeRoleConfidential> {
|
||||
let mut enc_attribute_list: Vec<PcdItemEncAttributeRoleConfidential> = Vec::new();
|
||||
|
||||
// tag_list
|
||||
let mut enc_attribute_tag_list_key =
|
||||
KeyEncryption::new(Some("tag_list".to_owned()), None, None);
|
||||
if let Ok(_new) = enc_attribute_tag_list_key.key_new_random() {
|
||||
let enc_attribute_tag_list = PcdItemEncAttributeRoleConfidential::new(
|
||||
"tag_list".to_owned(),
|
||||
enc_attribute_tag_list_key.enc_vec_string(self.meta_data.tag_list.clone()),
|
||||
enc_attribute_tag_list_key,
|
||||
);
|
||||
enc_attribute_list.push(enc_attribute_tag_list);
|
||||
}
|
||||
|
||||
// zone_list
|
||||
let mut enc_attribute_zone_list_key =
|
||||
KeyEncryption::new(Some("zone_list".to_owned()), None, None);
|
||||
if let Ok(_new) = enc_attribute_zone_list_key.key_new_random() {
|
||||
let enc_attribute_zone_list = PcdItemEncAttributeRoleConfidential::new(
|
||||
"zone_list".to_owned(),
|
||||
enc_attribute_zone_list_key.enc_vec_string(self.meta_data.zone_list.clone()),
|
||||
enc_attribute_zone_list_key,
|
||||
);
|
||||
enc_attribute_list.push(enc_attribute_zone_list);
|
||||
}
|
||||
|
||||
// label_list
|
||||
let mut enc_attribute_label_list_key =
|
||||
KeyEncryption::new(Some("label_list".to_owned()), None, None);
|
||||
if let Ok(_new) = enc_attribute_label_list_key.key_new_random() {
|
||||
let enc_attribute_label_list = PcdItemEncAttributeRoleConfidential::new(
|
||||
"label_list".to_owned(),
|
||||
enc_attribute_label_list_key.enc_vec_string(self.meta_data.label_list.clone()),
|
||||
enc_attribute_label_list_key,
|
||||
);
|
||||
enc_attribute_list.push(enc_attribute_label_list);
|
||||
}
|
||||
|
||||
// ref_list
|
||||
let mut enc_attribute_ref_list_key =
|
||||
KeyEncryption::new(Some("ref_list".to_owned()), None, None);
|
||||
if let Ok(_new) = enc_attribute_ref_list_key.key_new_random() {
|
||||
let enc_attribute_ref_list = PcdItemEncAttributeRoleConfidential::new(
|
||||
"ref_list".to_owned(),
|
||||
enc_attribute_ref_list_key.enc_vec_string(self.meta_data.ref_list.clone()),
|
||||
enc_attribute_ref_list_key,
|
||||
);
|
||||
enc_attribute_list.push(enc_attribute_ref_list);
|
||||
}
|
||||
|
||||
// data_list
|
||||
let mut enc_attribute_data_list_key =
|
||||
KeyEncryption::new(Some("data_list".to_owned()), None, None);
|
||||
if let Ok(_new) = enc_attribute_data_list_key.key_new_random() {
|
||||
let enc_attribute_data_list = PcdItemEncAttributeRoleConfidential::new(
|
||||
"data_list".to_owned(),
|
||||
enc_attribute_data_list_key.enc_vec_string(self.meta_data.data_list.clone()),
|
||||
enc_attribute_data_list_key,
|
||||
);
|
||||
enc_attribute_list.push(enc_attribute_data_list);
|
||||
}
|
||||
|
||||
// amount
|
||||
let mut enc_attribute_amount_key =
|
||||
KeyEncryption::new(Some("amount".to_owned()), None, None);
|
||||
if let Ok(_new) = enc_attribute_amount_key.key_new_random() {
|
||||
let enc_attribute_amount = PcdItemEncAttributeRoleConfidential::new(
|
||||
"amount".to_owned(),
|
||||
enc_attribute_amount_key.enc_amount(self.meta_data.amount.clone()),
|
||||
enc_attribute_amount_key,
|
||||
);
|
||||
enc_attribute_list.push(enc_attribute_amount);
|
||||
}
|
||||
|
||||
// number
|
||||
let mut enc_attribute_number_key =
|
||||
KeyEncryption::new(Some("number".to_owned()), None, None);
|
||||
if let Ok(_new) = enc_attribute_number_key.key_new_random() {
|
||||
let enc_attribute_number = PcdItemEncAttributeRoleConfidential::new(
|
||||
"number".to_owned(),
|
||||
enc_attribute_number_key.enc_number(self.meta_data.number.clone()),
|
||||
enc_attribute_number_key,
|
||||
);
|
||||
enc_attribute_list.push(enc_attribute_number);
|
||||
}
|
||||
|
||||
// render_template_list
|
||||
let mut enc_attribute_render_template_list_key =
|
||||
KeyEncryption::new(Some("render_template_list".to_owned()), None, None);
|
||||
if let Ok(_new) = enc_attribute_render_template_list_key.key_new_random() {
|
||||
let enc_attribute_render_template_list = PcdItemEncAttributeRoleConfidential::new(
|
||||
"render_template_list".to_owned(),
|
||||
enc_attribute_render_template_list_key
|
||||
.enc_vec_string(self.meta_data.render_template_list.clone()),
|
||||
enc_attribute_render_template_list_key,
|
||||
);
|
||||
enc_attribute_list.push(enc_attribute_render_template_list);
|
||||
}
|
||||
|
||||
// legal_text_list
|
||||
let mut enc_attribute_legal_text_list_key =
|
||||
KeyEncryption::new(Some("legal_text_list".to_owned()), None, None);
|
||||
if let Ok(_new) = enc_attribute_legal_text_list_key.key_new_random() {
|
||||
let enc_attribute_legal_text_list = PcdItemEncAttributeRoleConfidential::new(
|
||||
"legal_text_list".to_owned(),
|
||||
enc_attribute_legal_text_list_key
|
||||
.enc_vec_string(self.meta_data.legal_text_list.clone()),
|
||||
enc_attribute_legal_text_list_key,
|
||||
);
|
||||
enc_attribute_list.push(enc_attribute_legal_text_list);
|
||||
}
|
||||
|
||||
// key_list
|
||||
let mut enc_attribute_key_list_key =
|
||||
KeyEncryption::new(Some("key_list".to_owned()), None, None);
|
||||
if let Ok(_new) = enc_attribute_key_list_key.key_new_random() {
|
||||
let enc_attribute_key_list = PcdItemEncAttributeRoleConfidential::new(
|
||||
"key_list".to_owned(),
|
||||
enc_attribute_key_list_key.enc_vec_key_encryption(self.meta_data.key_list.clone()),
|
||||
enc_attribute_key_list_key,
|
||||
);
|
||||
enc_attribute_list.push(enc_attribute_key_list);
|
||||
}
|
||||
|
||||
return enc_attribute_list;
|
||||
}
|
||||
|
||||
// Additional
|
||||
}
|
54
src/models/mod.rs
Normal file
54
src/models/mod.rs
Normal file
@ -0,0 +1,54 @@
|
||||
pub mod commitment_method;
|
||||
pub mod condition_cap;
|
||||
pub mod condition_commitment;
|
||||
pub mod condition_deposit;
|
||||
pub mod condition_orchestration;
|
||||
pub mod condition_payment;
|
||||
pub mod condition_prd_address_set;
|
||||
pub mod condition_publish;
|
||||
pub mod deposit_method;
|
||||
pub mod item;
|
||||
pub mod item_artefact;
|
||||
pub mod item_commitment;
|
||||
pub mod item_deposit;
|
||||
pub mod item_enum;
|
||||
pub mod item_member;
|
||||
pub mod item_payment;
|
||||
pub mod item_peer;
|
||||
pub mod item_process;
|
||||
pub mod key_encryption;
|
||||
pub mod message;
|
||||
pub mod message_client;
|
||||
pub mod message_connect;
|
||||
pub mod metadata;
|
||||
pub mod metadata_contract_public;
|
||||
pub mod metadata_private;
|
||||
pub mod metadata_role_confidential;
|
||||
pub mod pagination;
|
||||
pub mod payment_method;
|
||||
pub mod pcd_item_enc;
|
||||
pub mod pcd_item_enc_attribute_private;
|
||||
pub mod pcd_item_enc_attribute_public;
|
||||
pub mod pcd_item_enc_attribute_role_confidential;
|
||||
pub mod pcd_item_generic_enc;
|
||||
pub mod request;
|
||||
pub mod request_pcd;
|
||||
pub mod request_prd;
|
||||
pub mod request_prd_confirm;
|
||||
pub mod request_prd_key_backup;
|
||||
pub mod request_prd_key_hello;
|
||||
pub mod request_prd_list;
|
||||
pub mod request_prd_message;
|
||||
pub mod request_prd_response;
|
||||
pub mod request_prd_update;
|
||||
pub mod role;
|
||||
pub mod role_artefact;
|
||||
pub mod role_commitment;
|
||||
pub mod role_deposit;
|
||||
pub mod role_member;
|
||||
pub mod role_payment;
|
||||
pub mod role_peer;
|
||||
pub mod role_process;
|
||||
pub mod roles_group;
|
||||
pub mod shared_peer;
|
||||
pub mod shared_process;
|
28
src/models/pagination.rs
Normal file
28
src/models/pagination.rs
Normal file
@ -0,0 +1,28 @@
|
||||
use rocket::FromForm;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(
|
||||
Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, FromForm,
|
||||
)]
|
||||
|
||||
pub struct Pagination {
|
||||
pub start: usize,
|
||||
pub number: usize,
|
||||
pub page_index: usize,
|
||||
}
|
||||
|
||||
impl Pagination {
|
||||
pub fn new(start: usize, number: usize, page_index: usize) -> Self {
|
||||
Pagination {
|
||||
start,
|
||||
number,
|
||||
page_index,
|
||||
}
|
||||
}
|
||||
pub fn display_info(&self) {
|
||||
println!("Pagination:");
|
||||
println!("Start: {}", self.start);
|
||||
println!("Number: {}", self.number);
|
||||
println!("Page Index: {}", self.page_index);
|
||||
}
|
||||
}
|
11
src/models/payment_method.rs
Normal file
11
src/models/payment_method.rs
Normal file
@ -0,0 +1,11 @@
|
||||
use rocket::FromForm;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(
|
||||
Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, FromForm,
|
||||
)]
|
||||
|
||||
pub struct PaymentMethod {
|
||||
pub method: String,
|
||||
}
|
||||
impl PaymentMethod {}
|
66
src/models/pcd_item_enc.rs
Normal file
66
src/models/pcd_item_enc.rs
Normal file
@ -0,0 +1,66 @@
|
||||
use rocket::FromForm;
|
||||
use std::hash::Hash;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::{
|
||||
pcd_item_enc_attribute_private::PcdItemEncAttributePrivate,
|
||||
pcd_item_enc_attribute_public::PcdItemEncAttributePublic,
|
||||
pcd_item_enc_attribute_role_confidential::PcdItemEncAttributeRoleConfidential,
|
||||
};
|
||||
|
||||
#[derive(
|
||||
Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, FromForm,
|
||||
)]
|
||||
|
||||
pub struct PcdItemEnc {
|
||||
pub version: i64,
|
||||
pub item_type: String,
|
||||
pub name: String,
|
||||
pub pagination_number_per_pcd: u32,
|
||||
pub pcd_item_enc_attribute_public_list: Vec<PcdItemEncAttributePublic>,
|
||||
pub pcd_item_enc_attribute_role_confidential_list: Vec<PcdItemEncAttributeRoleConfidential>,
|
||||
pub pcd_item_enc_attribute_private_list: Vec<PcdItemEncAttributePrivate>,
|
||||
}
|
||||
|
||||
impl PcdItemEnc {
|
||||
pub fn new(
|
||||
version: i64,
|
||||
item_type: String,
|
||||
name: String,
|
||||
pagination_number_per_pcd: u32,
|
||||
pcd_item_enc_attribute_public_list: Vec<PcdItemEncAttributePublic>,
|
||||
pcd_item_enc_attribute_role_confidential_list: Vec<PcdItemEncAttributeRoleConfidential>,
|
||||
pcd_item_enc_attribute_private_list: Vec<PcdItemEncAttributePrivate>,
|
||||
) -> Self {
|
||||
PcdItemEnc {
|
||||
version,
|
||||
item_type,
|
||||
name,
|
||||
pagination_number_per_pcd,
|
||||
pcd_item_enc_attribute_public_list,
|
||||
pcd_item_enc_attribute_role_confidential_list,
|
||||
pcd_item_enc_attribute_private_list,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn display_info(&self) {
|
||||
println!("PcdItemEnc:");
|
||||
println!("Public Attributes:");
|
||||
for attr in &self.pcd_item_enc_attribute_public_list {
|
||||
attr.display_info();
|
||||
}
|
||||
|
||||
println!("Role Confidential Attributes:");
|
||||
for attr in &self.pcd_item_enc_attribute_role_confidential_list {
|
||||
attr.display_info();
|
||||
}
|
||||
|
||||
println!("Private Attributes:");
|
||||
for attr in &self.pcd_item_enc_attribute_private_list {
|
||||
attr.display_info();
|
||||
}
|
||||
}
|
||||
|
||||
// Additional methods for PcdItemEnc can be added here
|
||||
}
|
30
src/models/pcd_item_enc_attribute_private.rs
Normal file
30
src/models/pcd_item_enc_attribute_private.rs
Normal file
@ -0,0 +1,30 @@
|
||||
use rocket::FromForm;
|
||||
use std::hash::Hash;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(
|
||||
Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, FromForm, Hash, PartialOrd, Ord,
|
||||
)]
|
||||
|
||||
pub struct PcdItemEncAttributePrivate {
|
||||
pub attribute_name: String,
|
||||
pub data_enc: String, // Assuming the encrypted data is represented as a String
|
||||
}
|
||||
|
||||
impl PcdItemEncAttributePrivate {
|
||||
pub fn new(attribute_name: String, data_enc: String) -> Self {
|
||||
PcdItemEncAttributePrivate {
|
||||
attribute_name,
|
||||
data_enc,
|
||||
}
|
||||
}
|
||||
// Method to display information
|
||||
pub fn display_info(&self) {
|
||||
println!("PcdItemEncAttributePrivate:");
|
||||
println!("Attribute Name: {}", self.attribute_name);
|
||||
println!("Data Enc: {}", self.data_enc);
|
||||
}
|
||||
|
||||
// Additional methods for PcdItemEncAttributePrivate can be added here
|
||||
}
|
28
src/models/pcd_item_enc_attribute_public.rs
Normal file
28
src/models/pcd_item_enc_attribute_public.rs
Normal file
@ -0,0 +1,28 @@
|
||||
use rocket::FromForm;
|
||||
use std::hash::Hash;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(
|
||||
Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, FromForm, Hash, PartialOrd, Ord,
|
||||
)]
|
||||
|
||||
pub struct PcdItemEncAttributePublic {
|
||||
pub attribute_name: String,
|
||||
pub data_enc: String, // Assuming the encrypted data is represented as a String
|
||||
}
|
||||
impl PcdItemEncAttributePublic {
|
||||
pub fn new(attribute_name: String, data_enc: String) -> Self {
|
||||
PcdItemEncAttributePublic {
|
||||
attribute_name,
|
||||
data_enc,
|
||||
}
|
||||
}
|
||||
pub fn display_info(&self) {
|
||||
println!("PcdItemEncAttributePublic:");
|
||||
println!("Attribute Name: {}", self.attribute_name);
|
||||
println!("Data Enc: {}", self.data_enc);
|
||||
}
|
||||
|
||||
// Additional methods for PcdItemEncAttributePublic can be added here
|
||||
}
|
32
src/models/pcd_item_enc_attribute_role_confidential.rs
Normal file
32
src/models/pcd_item_enc_attribute_role_confidential.rs
Normal file
@ -0,0 +1,32 @@
|
||||
use rocket::FromForm;
|
||||
use std::hash::Hash;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::key_encryption::KeyEncryption;
|
||||
|
||||
#[derive(
|
||||
Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, FromForm, Hash, PartialOrd, Ord,
|
||||
)]
|
||||
|
||||
pub struct PcdItemEncAttributeRoleConfidential {
|
||||
pub attribute_name: String,
|
||||
pub data_enc: String, // Assuming the encrypted data is represented as a String
|
||||
pub key: KeyEncryption, // Assuming the encrypted data is represented as a String
|
||||
}
|
||||
|
||||
impl PcdItemEncAttributeRoleConfidential {
|
||||
pub fn new(attribute_name: String, data_enc: String, key: KeyEncryption) -> Self {
|
||||
PcdItemEncAttributeRoleConfidential {
|
||||
attribute_name,
|
||||
data_enc,
|
||||
key,
|
||||
}
|
||||
}
|
||||
pub fn display_info(&self) {
|
||||
println!("PcdItemEncAttributeRoleConfidential:");
|
||||
println!("Attribute Name: {}", self.attribute_name);
|
||||
println!("Data Enc: {}", self.data_enc);
|
||||
self.key.display_info();
|
||||
}
|
||||
}
|
66
src/models/pcd_item_generic_enc.rs
Normal file
66
src/models/pcd_item_generic_enc.rs
Normal file
@ -0,0 +1,66 @@
|
||||
use rocket::FromForm;
|
||||
use std::hash::Hash;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::{
|
||||
pcd_item_enc::PcdItemEnc, pcd_item_enc_attribute_private::PcdItemEncAttributePrivate,
|
||||
pcd_item_enc_attribute_public::PcdItemEncAttributePublic,
|
||||
pcd_item_enc_attribute_role_confidential::PcdItemEncAttributeRoleConfidential,
|
||||
};
|
||||
|
||||
#[derive(
|
||||
Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, FromForm,
|
||||
)]
|
||||
|
||||
pub struct PcdItemGenericEnc {
|
||||
pub item_enc: PcdItemEnc,
|
||||
pub pcd_item_enc_attribute_public_list: Option<Vec<PcdItemEncAttributePublic>>,
|
||||
pub pcd_item_enc_attribute_role_confidential_list:
|
||||
Option<Vec<PcdItemEncAttributeRoleConfidential>>,
|
||||
pub pcd_item_enc_attribute_private_list: Option<Vec<PcdItemEncAttributePrivate>>,
|
||||
}
|
||||
|
||||
impl PcdItemGenericEnc {
|
||||
pub fn new(
|
||||
item_enc: PcdItemEnc,
|
||||
pcd_item_enc_attribute_public_list: Option<Vec<PcdItemEncAttributePublic>>,
|
||||
pcd_item_enc_attribute_role_confidential_list: Option<
|
||||
Vec<PcdItemEncAttributeRoleConfidential>,
|
||||
>,
|
||||
pcd_item_enc_attribute_private_list: Option<Vec<PcdItemEncAttributePrivate>>,
|
||||
) -> Self {
|
||||
PcdItemGenericEnc {
|
||||
item_enc,
|
||||
pcd_item_enc_attribute_public_list,
|
||||
pcd_item_enc_attribute_role_confidential_list,
|
||||
pcd_item_enc_attribute_private_list,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn display_info(&self) {
|
||||
println!("PcdItemEnc:");
|
||||
println!("Public Attributes:");
|
||||
for attr in &self.pcd_item_enc_attribute_public_list {
|
||||
for attr_sub in attr {
|
||||
attr_sub.display_info();
|
||||
}
|
||||
}
|
||||
|
||||
println!("Role Confidential Attributes:");
|
||||
for attr in &self.pcd_item_enc_attribute_role_confidential_list {
|
||||
for attr_sub in attr {
|
||||
attr_sub.display_info();
|
||||
}
|
||||
}
|
||||
|
||||
println!("Private Attributes:");
|
||||
for attr in &self.pcd_item_enc_attribute_private_list {
|
||||
for attr_sub in attr {
|
||||
attr_sub.display_info();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Additional methods for PcdItemEnc can be added here
|
||||
}
|
49
src/models/request.rs
Normal file
49
src/models/request.rs
Normal file
@ -0,0 +1,49 @@
|
||||
use rocket::FromForm;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(
|
||||
Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, FromForm,
|
||||
)]
|
||||
|
||||
pub struct Request {
|
||||
pub item_name: Option<String>,
|
||||
pub request_type: String, // `type` is a reserved keyword in Rust, renamed to `request_type`
|
||||
pub version: i64,
|
||||
pub process_hash: String,
|
||||
pub pcd_reference_hash: Option<String>,
|
||||
pub item_reference_hash: Option<String>,
|
||||
}
|
||||
|
||||
impl Request {
|
||||
pub fn new(
|
||||
item_name: Option<String>,
|
||||
request_type: String,
|
||||
version: i64,
|
||||
process_hash: String,
|
||||
pcd_reference_hash: Option<String>,
|
||||
item_reference_hash: Option<String>,
|
||||
) -> Self {
|
||||
let req = Request {
|
||||
item_name,
|
||||
request_type,
|
||||
version,
|
||||
process_hash,
|
||||
pcd_reference_hash,
|
||||
item_reference_hash,
|
||||
};
|
||||
return req;
|
||||
}
|
||||
|
||||
// Fonction pour afficher ou retourner les informations
|
||||
pub fn display_info(&self) -> String {
|
||||
format!(
|
||||
"Item Name: {}, Request Type: {}, Version: {}, Process Hash: {}, PCD Reference Hash: {}, Item Reference Hash: {}",
|
||||
self.item_name.as_ref().unwrap_or(&"None".to_string()),
|
||||
self.request_type,
|
||||
self.version,
|
||||
self.process_hash,
|
||||
self.pcd_reference_hash.as_ref().unwrap_or(&"None".to_string()),
|
||||
self.item_reference_hash.as_ref().unwrap_or(&"None".to_string()),
|
||||
)
|
||||
}
|
||||
}
|
146
src/models/request_pcd.rs
Normal file
146
src/models/request_pcd.rs
Normal file
@ -0,0 +1,146 @@
|
||||
use rocket::FromForm;
|
||||
use std::{
|
||||
collections::hash_map::DefaultHasher,
|
||||
hash::{Hash, Hasher},
|
||||
};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::{
|
||||
item_enum::ItemEnum, key_encryption::KeyEncryption, message_client::MessageClient,
|
||||
pagination::Pagination, pcd_item_generic_enc::PcdItemGenericEnc, request::Request,
|
||||
shared_peer::SharedPeer, shared_process::SharedProcess,
|
||||
};
|
||||
|
||||
#[derive(
|
||||
Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, FromForm,
|
||||
)]
|
||||
|
||||
pub struct RequestPcd {
|
||||
pub request: Request, // Assuming Request is a predefined struct
|
||||
pub item_list: Vec<PcdItemGenericEnc>,
|
||||
pub pagination: Pagination, // Assuming Pagination is a predefined struct
|
||||
}
|
||||
|
||||
impl RequestPcd {
|
||||
pub const TYPE: &'static str = "pcd";
|
||||
pub fn new(
|
||||
request_item_name: Option<String>,
|
||||
request_version: i64,
|
||||
request_process_hash: String,
|
||||
request_pcd_reference_hash: Option<String>,
|
||||
request_item_reference_hash: Option<String>,
|
||||
item_list: Vec<ItemEnum>,
|
||||
pagination: Pagination,
|
||||
process_public_enc_key: KeyEncryption,
|
||||
member_private_enc_key: KeyEncryption,
|
||||
) -> Self {
|
||||
let request = Request::new(
|
||||
request_item_name,
|
||||
Self::TYPE.to_string(),
|
||||
request_version,
|
||||
request_process_hash,
|
||||
request_pcd_reference_hash,
|
||||
request_item_reference_hash,
|
||||
);
|
||||
|
||||
// TODO: encrypt item_list
|
||||
let mut item_enc_list: Vec<PcdItemGenericEnc> = Vec::new();
|
||||
|
||||
item_list.iter().for_each(|item| match item {
|
||||
ItemEnum::Process(item_process) => {
|
||||
let item_enc = item_process.enc(
|
||||
process_public_enc_key.clone(),
|
||||
member_private_enc_key.clone(),
|
||||
);
|
||||
item_enc_list.push(item_enc);
|
||||
}
|
||||
ItemEnum::Member(item_member) => {
|
||||
let item_enc = item_member.enc(
|
||||
process_public_enc_key.clone(),
|
||||
member_private_enc_key.clone(),
|
||||
);
|
||||
item_enc_list.push(item_enc);
|
||||
}
|
||||
ItemEnum::Artefact(item_artefact) => {
|
||||
let item_enc = item_artefact.enc(
|
||||
process_public_enc_key.clone(),
|
||||
member_private_enc_key.clone(),
|
||||
);
|
||||
item_enc_list.push(item_enc);
|
||||
}
|
||||
ItemEnum::Peer(item_peer) => {
|
||||
let item_enc = item_peer.enc(
|
||||
process_public_enc_key.clone(),
|
||||
member_private_enc_key.clone(),
|
||||
);
|
||||
item_enc_list.push(item_enc);
|
||||
}
|
||||
ItemEnum::Payment(item_payment) => {
|
||||
let item_enc = item_payment.enc(
|
||||
process_public_enc_key.clone(),
|
||||
member_private_enc_key.clone(),
|
||||
);
|
||||
item_enc_list.push(item_enc);
|
||||
}
|
||||
ItemEnum::Deposit(item_deposit) => {
|
||||
let item_enc = item_deposit.enc(
|
||||
process_public_enc_key.clone(),
|
||||
member_private_enc_key.clone(),
|
||||
);
|
||||
item_enc_list.push(item_enc);
|
||||
}
|
||||
ItemEnum::Commitment(item_commitment) => {
|
||||
let item_enc = item_commitment.enc(
|
||||
process_public_enc_key.clone(),
|
||||
member_private_enc_key.clone(),
|
||||
);
|
||||
item_enc_list.push(item_enc);
|
||||
}
|
||||
});
|
||||
|
||||
RequestPcd {
|
||||
request,
|
||||
item_list: item_enc_list,
|
||||
pagination,
|
||||
}
|
||||
}
|
||||
pub fn display_info(&self) {
|
||||
println!("RequestPcd:");
|
||||
println!("Request:");
|
||||
self.request.display_info();
|
||||
|
||||
println!("Item List:");
|
||||
for item in &self.item_list {
|
||||
item.display_info();
|
||||
}
|
||||
|
||||
println!("Pagination:");
|
||||
self.pagination.display_info();
|
||||
}
|
||||
|
||||
pub fn to_message(
|
||||
&self,
|
||||
process_public_enc_key: KeyEncryption,
|
||||
message_shared_peer_list: Vec<SharedPeer>,
|
||||
message_shared_process_list: Vec<SharedProcess>,
|
||||
message_faucet_sp_address: String,
|
||||
pow_pathern: String,
|
||||
pow_difficulty: usize,
|
||||
) -> MessageClient {
|
||||
let mut hasher: DefaultHasher = DefaultHasher::new();
|
||||
self.hash(&mut hasher);
|
||||
let request_hash = hasher.finish().to_string();
|
||||
let request_enc: String = process_public_enc_key.enc_pcd(self.clone()).to_string();
|
||||
|
||||
MessageClient::new(
|
||||
request_enc,
|
||||
request_hash,
|
||||
message_shared_peer_list,
|
||||
message_shared_process_list,
|
||||
message_faucet_sp_address,
|
||||
pow_pathern,
|
||||
pow_difficulty,
|
||||
)
|
||||
}
|
||||
}
|
113
src/models/request_prd.rs
Normal file
113
src/models/request_prd.rs
Normal file
@ -0,0 +1,113 @@
|
||||
use rocket::FromForm;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::hash::Hash;
|
||||
|
||||
use super::{key_encryption::KeyEncryption, request::Request};
|
||||
#[derive(
|
||||
Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, FromForm,
|
||||
)]
|
||||
pub struct KeyRoleConfidential {
|
||||
pub attribute_name: String,
|
||||
pub key: KeyEncryption,
|
||||
pub algorithm_name: String,
|
||||
}
|
||||
|
||||
impl KeyRoleConfidential {
|
||||
pub fn new(attribute_name: String, key: KeyEncryption, algorithm_name: String) -> Self {
|
||||
KeyRoleConfidential {
|
||||
attribute_name,
|
||||
key,
|
||||
algorithm_name,
|
||||
}
|
||||
}
|
||||
|
||||
// Fonction pour afficher ou retourner les informations
|
||||
pub fn display_info(&self) -> String {
|
||||
format!(
|
||||
"Attribute Name: {}, Key: {:?}, Algorithm: {}",
|
||||
self.attribute_name,
|
||||
self.key, // Utilise {:?} si KeyEncryption implémente Debug
|
||||
self.algorithm_name
|
||||
)
|
||||
}
|
||||
|
||||
// Additional methods for KeyRoleConfidential can be added here
|
||||
}
|
||||
|
||||
#[derive(
|
||||
Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, FromForm, Hash, PartialOrd, Ord,
|
||||
)]
|
||||
pub struct RequestPrd {
|
||||
pub request: Request, // Assuming Request is a predefined struct
|
||||
pub pcd_keys_role_confidential_list_enc_by_shared_secret: String,
|
||||
pub message_public: Option<String>,
|
||||
pub message_confidential: Option<String>,
|
||||
pub message_private: Option<String>,
|
||||
pub sp_address_to: String,
|
||||
pub sp_address_from: String,
|
||||
pub sp_address_reply: String,
|
||||
pub timestamp_declared: u64, // Assuming a Unix timestamp
|
||||
pub role_name_from: String,
|
||||
pub role_name_to: String,
|
||||
}
|
||||
|
||||
impl RequestPrd {
|
||||
pub const TYPE: &'static str = "prd";
|
||||
pub fn new(
|
||||
request_item_name: Option<String>,
|
||||
request_type: String,
|
||||
request_version: i64,
|
||||
request_process_hash: String,
|
||||
request_pcd_reference_hash: Option<String>,
|
||||
request_item_reference_hash: Option<String>,
|
||||
pcd_keys_role_confidential_list_enc_by_shared_secret: String,
|
||||
message_public: Option<String>,
|
||||
message_confidential: Option<String>,
|
||||
message_private: Option<String>,
|
||||
sp_address_to: String,
|
||||
sp_address_from: String,
|
||||
sp_address_reply: String,
|
||||
timestamp_declared: u64,
|
||||
role_name_from: String,
|
||||
role_name_to: String,
|
||||
) -> Self {
|
||||
let request = Request::new(
|
||||
request_item_name,
|
||||
request_type,
|
||||
request_version,
|
||||
request_process_hash,
|
||||
request_pcd_reference_hash,
|
||||
request_item_reference_hash,
|
||||
);
|
||||
RequestPrd {
|
||||
request,
|
||||
pcd_keys_role_confidential_list_enc_by_shared_secret,
|
||||
message_public,
|
||||
message_confidential,
|
||||
message_private,
|
||||
sp_address_to,
|
||||
sp_address_from,
|
||||
sp_address_reply,
|
||||
timestamp_declared,
|
||||
role_name_from,
|
||||
role_name_to,
|
||||
}
|
||||
}
|
||||
|
||||
// Fonction pour afficher ou retourner les informations
|
||||
pub fn display_info(&self) -> String {
|
||||
format!(
|
||||
"Request: {:?}, PCD Keys Role Confidential: {:?}, Message Public: {}, Message Confidential: {}, Message Private: {}, SP Address From: {}, SP Address Reply: {}, Timestamp Declared: {}, Role Name From: {}, Role Name To: {}",
|
||||
self.request,
|
||||
self.pcd_keys_role_confidential_list_enc_by_shared_secret,
|
||||
self.message_public.as_ref().unwrap(),
|
||||
self.message_confidential.as_ref().unwrap(),
|
||||
self.message_private.as_ref().unwrap(),
|
||||
self.sp_address_from,
|
||||
self.sp_address_reply,
|
||||
self.timestamp_declared,
|
||||
self.role_name_from,
|
||||
self.role_name_to,
|
||||
)
|
||||
}
|
||||
}
|
103
src/models/request_prd_confirm.rs
Normal file
103
src/models/request_prd_confirm.rs
Normal file
@ -0,0 +1,103 @@
|
||||
use rocket::FromForm;
|
||||
use std::{
|
||||
collections::hash_map::DefaultHasher,
|
||||
hash::{Hash, Hasher},
|
||||
};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::{
|
||||
key_encryption::KeyEncryption, message_client::MessageClient, request_prd::RequestPrd,
|
||||
shared_peer::SharedPeer, shared_process::SharedProcess,
|
||||
};
|
||||
#[derive(
|
||||
Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, FromForm,
|
||||
)]
|
||||
|
||||
pub struct RequestPrdConfirm {
|
||||
pub prd: RequestPrd,
|
||||
pub code_confirm_enc_by_shared_secret: String,
|
||||
}
|
||||
|
||||
impl RequestPrdConfirm {
|
||||
pub const TYPE: &'static str = "prd_confirm";
|
||||
pub fn new(
|
||||
request_item_name: Option<String>,
|
||||
request_version: i64,
|
||||
request_process_hash: String,
|
||||
request_pcd_reference_hash: Option<String>,
|
||||
request_item_reference_hash: Option<String>,
|
||||
pcd_keys_role_confidential_list_enc_by_shared_secret: String,
|
||||
message_public: Option<String>,
|
||||
message_confidential: Option<String>,
|
||||
message_private: Option<String>,
|
||||
sp_address_to: String,
|
||||
sp_address_from: String,
|
||||
sp_address_reply: String,
|
||||
timestamp_declared: u64,
|
||||
role_name_from: String,
|
||||
role_name_to: String,
|
||||
code_confirm_enc_by_shared_secret: String,
|
||||
) -> Self {
|
||||
let request_type = Self::TYPE.to_string();
|
||||
let prd = RequestPrd::new(
|
||||
request_item_name,
|
||||
request_type,
|
||||
request_version,
|
||||
request_process_hash,
|
||||
request_pcd_reference_hash,
|
||||
request_item_reference_hash,
|
||||
pcd_keys_role_confidential_list_enc_by_shared_secret,
|
||||
message_public,
|
||||
message_confidential,
|
||||
message_private,
|
||||
sp_address_to,
|
||||
sp_address_from,
|
||||
sp_address_reply,
|
||||
timestamp_declared,
|
||||
role_name_from,
|
||||
role_name_to,
|
||||
);
|
||||
RequestPrdConfirm {
|
||||
prd,
|
||||
code_confirm_enc_by_shared_secret,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_message(
|
||||
&self,
|
||||
process_public_enc_key: KeyEncryption,
|
||||
message_shared_peer_list: Vec<SharedPeer>,
|
||||
message_shared_process_list: Vec<SharedProcess>,
|
||||
message_faucet_sp_address: String,
|
||||
pow_pathern: String,
|
||||
pow_difficulty: usize,
|
||||
) -> MessageClient {
|
||||
let mut hasher: DefaultHasher = DefaultHasher::new();
|
||||
self.hash(&mut hasher);
|
||||
let request_hash = hasher.finish().to_string();
|
||||
let request_enc: String = process_public_enc_key
|
||||
.enc_prd_confirm(self.clone())
|
||||
.to_string();
|
||||
|
||||
MessageClient::new(
|
||||
request_enc,
|
||||
request_hash,
|
||||
message_shared_peer_list,
|
||||
message_shared_process_list,
|
||||
message_faucet_sp_address,
|
||||
pow_pathern,
|
||||
pow_difficulty,
|
||||
)
|
||||
}
|
||||
// display_info method
|
||||
pub fn display_info(&self) {
|
||||
println!("RequestPrdConfirm:");
|
||||
println!("PRD:");
|
||||
self.prd.display_info(); // Display information of RequestPrd
|
||||
println!(
|
||||
"Code Confirm (Encrypted by Shared Secret): {}",
|
||||
self.code_confirm_enc_by_shared_secret
|
||||
);
|
||||
}
|
||||
}
|
111
src/models/request_prd_key_backup.rs
Normal file
111
src/models/request_prd_key_backup.rs
Normal file
@ -0,0 +1,111 @@
|
||||
use rocket::FromForm;
|
||||
use std::{
|
||||
collections::hash_map::DefaultHasher,
|
||||
hash::{Hash, Hasher},
|
||||
};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::{
|
||||
key_encryption::KeyEncryption, message_client::MessageClient, request_prd::RequestPrd,
|
||||
shared_peer::SharedPeer, shared_process::SharedProcess,
|
||||
};
|
||||
#[derive(
|
||||
Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, FromForm,
|
||||
)]
|
||||
|
||||
pub struct RequestPrdKeyBackup {
|
||||
pub prd: RequestPrd,
|
||||
pub device_footprint_enc_by_sp_shared_secret: String,
|
||||
pub part_1_enc_hash_enc_by_sp_shared_secret: String,
|
||||
pub shard_enc_by_sp_shared_secret: String,
|
||||
}
|
||||
|
||||
impl RequestPrdKeyBackup {
|
||||
pub const TYPE: &'static str = "prd_key_backup";
|
||||
pub fn new(
|
||||
request_item_name: Option<String>,
|
||||
request_version: i64,
|
||||
request_process_hash: String,
|
||||
request_pcd_reference_hash: Option<String>,
|
||||
request_item_reference_hash: Option<String>,
|
||||
pcd_keys_role_confidential_list_enc_by_shared_secret: String,
|
||||
message_public: Option<String>,
|
||||
message_confidential: Option<String>,
|
||||
message_private: Option<String>,
|
||||
sp_address_to: String,
|
||||
sp_address_from: String,
|
||||
sp_address_reply: String,
|
||||
timestamp_declared: u64,
|
||||
role_name_from: String,
|
||||
role_name_to: String,
|
||||
|
||||
device_footprint_enc_by_sp_shared_secret: String,
|
||||
part_1_enc_hash_enc_by_sp_shared_secret: String,
|
||||
shard_enc_by_sp_shared_secret: String,
|
||||
) -> Self {
|
||||
let request_type = Self::TYPE.to_string();
|
||||
let prd = RequestPrd::new(
|
||||
request_item_name,
|
||||
request_type,
|
||||
request_version,
|
||||
request_process_hash,
|
||||
request_pcd_reference_hash,
|
||||
request_item_reference_hash,
|
||||
pcd_keys_role_confidential_list_enc_by_shared_secret,
|
||||
message_public,
|
||||
message_confidential,
|
||||
message_private,
|
||||
sp_address_to,
|
||||
sp_address_from,
|
||||
sp_address_reply,
|
||||
timestamp_declared,
|
||||
role_name_from,
|
||||
role_name_to,
|
||||
);
|
||||
RequestPrdKeyBackup {
|
||||
prd,
|
||||
device_footprint_enc_by_sp_shared_secret,
|
||||
part_1_enc_hash_enc_by_sp_shared_secret,
|
||||
shard_enc_by_sp_shared_secret,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_message(
|
||||
&self,
|
||||
process_public_enc_key: KeyEncryption,
|
||||
message_shared_peer_list: Vec<SharedPeer>,
|
||||
message_shared_process_list: Vec<SharedProcess>,
|
||||
message_faucet_sp_address: String,
|
||||
pow_pathern: String,
|
||||
pow_difficulty: usize,
|
||||
) -> MessageClient {
|
||||
let mut hasher: DefaultHasher = DefaultHasher::new();
|
||||
self.hash(&mut hasher);
|
||||
let request_hash = hasher.finish().to_string();
|
||||
let request_enc: String = process_public_enc_key
|
||||
.enc_prd_key_backup(self.clone())
|
||||
.to_string();
|
||||
|
||||
MessageClient::new(
|
||||
request_enc,
|
||||
request_hash,
|
||||
message_shared_peer_list,
|
||||
message_shared_process_list,
|
||||
message_faucet_sp_address,
|
||||
pow_pathern,
|
||||
pow_difficulty,
|
||||
)
|
||||
}
|
||||
|
||||
// Fonction pour afficher ou retourner les informations
|
||||
pub fn display_info(&self) -> String {
|
||||
format!(
|
||||
"PRD: {:?}, Device Footprint Encrypted: {}, Part 1 Encrypted Hash: {}, Shard Encrypted: {}",
|
||||
self.prd,
|
||||
self.device_footprint_enc_by_sp_shared_secret,
|
||||
self.part_1_enc_hash_enc_by_sp_shared_secret,
|
||||
self.shard_enc_by_sp_shared_secret
|
||||
)
|
||||
}
|
||||
}
|
101
src/models/request_prd_key_hello.rs
Normal file
101
src/models/request_prd_key_hello.rs
Normal file
@ -0,0 +1,101 @@
|
||||
use rocket::FromForm;
|
||||
use std::{
|
||||
collections::hash_map::DefaultHasher,
|
||||
hash::{Hash, Hasher},
|
||||
};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::{
|
||||
key_encryption::KeyEncryption, message_client::MessageClient, request_prd::RequestPrd,
|
||||
shared_peer::SharedPeer, shared_process::SharedProcess,
|
||||
};
|
||||
#[derive(
|
||||
Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, FromForm,
|
||||
)]
|
||||
|
||||
pub struct RequestPrdKeyHello {
|
||||
pub prd: RequestPrd,
|
||||
pub part_1_enc_hash_enc_by_sp_shared_secret: String,
|
||||
}
|
||||
|
||||
impl RequestPrdKeyHello {
|
||||
pub const TYPE: &'static str = "prd_key_hello";
|
||||
pub fn new(
|
||||
request_item_name: Option<String>,
|
||||
request_version: i64,
|
||||
request_process_hash: String,
|
||||
request_pcd_reference_hash: Option<String>,
|
||||
request_item_reference_hash: Option<String>,
|
||||
pcd_keys_role_confidential_list_enc_by_shared_secret: String,
|
||||
message_public: Option<String>,
|
||||
message_confidential: Option<String>,
|
||||
message_private: Option<String>,
|
||||
sp_address_to: String,
|
||||
sp_address_from: String,
|
||||
sp_address_reply: String,
|
||||
timestamp_declared: u64,
|
||||
role_name_from: String,
|
||||
role_name_to: String,
|
||||
part_1_enc_hash_enc_by_sp_shared_secret: String,
|
||||
) -> Self {
|
||||
let request_type = Self::TYPE.to_string();
|
||||
let prd = RequestPrd::new(
|
||||
request_item_name,
|
||||
request_type,
|
||||
request_version,
|
||||
request_process_hash,
|
||||
request_pcd_reference_hash,
|
||||
request_item_reference_hash,
|
||||
pcd_keys_role_confidential_list_enc_by_shared_secret,
|
||||
message_public,
|
||||
message_confidential,
|
||||
message_private,
|
||||
sp_address_to,
|
||||
sp_address_from,
|
||||
sp_address_reply,
|
||||
timestamp_declared,
|
||||
role_name_from,
|
||||
role_name_to,
|
||||
);
|
||||
RequestPrdKeyHello {
|
||||
prd,
|
||||
part_1_enc_hash_enc_by_sp_shared_secret,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_message(
|
||||
&self,
|
||||
process_public_enc_key: KeyEncryption,
|
||||
message_shared_peer_list: Vec<SharedPeer>,
|
||||
message_shared_process_list: Vec<SharedProcess>,
|
||||
message_faucet_sp_address: String,
|
||||
pow_pathern: String,
|
||||
pow_difficulty: usize,
|
||||
) -> MessageClient {
|
||||
let mut hasher: DefaultHasher = DefaultHasher::new();
|
||||
self.hash(&mut hasher);
|
||||
let request_hash = hasher.finish().to_string();
|
||||
let request_enc: String = process_public_enc_key
|
||||
.enc_prd_key_hello(self.clone())
|
||||
.to_string();
|
||||
|
||||
MessageClient::new(
|
||||
request_enc,
|
||||
request_hash,
|
||||
message_shared_peer_list,
|
||||
message_shared_process_list,
|
||||
message_faucet_sp_address,
|
||||
pow_pathern,
|
||||
pow_difficulty,
|
||||
)
|
||||
}
|
||||
|
||||
// Fonction pour afficher ou retourner les informations
|
||||
pub fn display_info(&self) -> String {
|
||||
format!(
|
||||
"PRD: {:?}, Part 1 Encrypted Hash: {}",
|
||||
self.prd, self.part_1_enc_hash_enc_by_sp_shared_secret
|
||||
)
|
||||
}
|
||||
}
|
93
src/models/request_prd_list.rs
Normal file
93
src/models/request_prd_list.rs
Normal file
@ -0,0 +1,93 @@
|
||||
use rocket::FromForm;
|
||||
use std::{
|
||||
collections::hash_map::DefaultHasher,
|
||||
hash::{Hash, Hasher},
|
||||
};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::{
|
||||
key_encryption::KeyEncryption, message_client::MessageClient, request_prd::RequestPrd,
|
||||
shared_peer::SharedPeer, shared_process::SharedProcess,
|
||||
};
|
||||
#[derive(
|
||||
Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, FromForm,
|
||||
)]
|
||||
|
||||
pub struct RequestPrdList {
|
||||
pub prd: RequestPrd,
|
||||
}
|
||||
|
||||
impl RequestPrdList {
|
||||
pub const TYPE: &'static str = "prd_list";
|
||||
pub fn new(
|
||||
request_item_name: Option<String>,
|
||||
request_version: i64,
|
||||
request_process_hash: String,
|
||||
request_pcd_reference_hash: Option<String>,
|
||||
request_item_reference_hash: Option<String>,
|
||||
pcd_keys_role_confidential_list_enc_by_shared_secret: String,
|
||||
message_public: Option<String>,
|
||||
message_confidential: Option<String>,
|
||||
message_private: Option<String>,
|
||||
sp_address_to: String,
|
||||
sp_address_from: String,
|
||||
sp_address_reply: String,
|
||||
timestamp_declared: u64,
|
||||
role_name_from: String,
|
||||
role_name_to: String,
|
||||
) -> Self {
|
||||
let request_type = Self::TYPE.to_string();
|
||||
let prd = RequestPrd::new(
|
||||
request_item_name,
|
||||
request_type,
|
||||
request_version,
|
||||
request_process_hash,
|
||||
request_pcd_reference_hash,
|
||||
request_item_reference_hash,
|
||||
pcd_keys_role_confidential_list_enc_by_shared_secret,
|
||||
message_public,
|
||||
message_confidential,
|
||||
message_private,
|
||||
sp_address_to,
|
||||
sp_address_from,
|
||||
sp_address_reply,
|
||||
timestamp_declared,
|
||||
role_name_from,
|
||||
role_name_to,
|
||||
);
|
||||
RequestPrdList { prd }
|
||||
}
|
||||
|
||||
pub fn to_message(
|
||||
&self,
|
||||
process_public_enc_key: KeyEncryption,
|
||||
message_shared_peer_list: Vec<SharedPeer>,
|
||||
message_shared_process_list: Vec<SharedProcess>,
|
||||
message_faucet_sp_address: String,
|
||||
pow_pathern: String,
|
||||
pow_difficulty: usize,
|
||||
) -> MessageClient {
|
||||
let mut hasher: DefaultHasher = DefaultHasher::new();
|
||||
self.hash(&mut hasher);
|
||||
let request_hash = hasher.finish().to_string();
|
||||
let request_enc: String = process_public_enc_key
|
||||
.enc_prd_list(self.clone())
|
||||
.to_string();
|
||||
|
||||
MessageClient::new(
|
||||
request_enc,
|
||||
request_hash,
|
||||
message_shared_peer_list,
|
||||
message_shared_process_list,
|
||||
message_faucet_sp_address,
|
||||
pow_pathern,
|
||||
pow_difficulty,
|
||||
)
|
||||
}
|
||||
|
||||
// Fonction pour afficher ou retourner les informations
|
||||
pub fn display_info(&self) -> String {
|
||||
format!("PRD: {:?}", self.prd)
|
||||
}
|
||||
}
|
92
src/models/request_prd_message.rs
Normal file
92
src/models/request_prd_message.rs
Normal file
@ -0,0 +1,92 @@
|
||||
use rocket::FromForm;
|
||||
use std::{
|
||||
collections::hash_map::DefaultHasher,
|
||||
hash::{Hash, Hasher},
|
||||
};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::{
|
||||
key_encryption::KeyEncryption, message_client::MessageClient, request_prd::RequestPrd,
|
||||
shared_peer::SharedPeer, shared_process::SharedProcess,
|
||||
};
|
||||
#[derive(
|
||||
Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, FromForm,
|
||||
)]
|
||||
|
||||
pub struct RequestPrdMessage {
|
||||
pub prd: RequestPrd,
|
||||
}
|
||||
|
||||
impl RequestPrdMessage {
|
||||
pub const TYPE: &'static str = "prd_message";
|
||||
pub fn new(
|
||||
request_item_name: Option<String>,
|
||||
request_version: i64,
|
||||
request_process_hash: String,
|
||||
request_pcd_reference_hash: Option<String>,
|
||||
request_item_reference_hash: Option<String>,
|
||||
pcd_keys_role_confidential_list_enc_by_shared_secret: String,
|
||||
message_public: Option<String>,
|
||||
message_confidential: Option<String>,
|
||||
message_private: Option<String>,
|
||||
sp_address_to: String,
|
||||
sp_address_from: String,
|
||||
sp_address_reply: String,
|
||||
timestamp_declared: u64,
|
||||
role_name_from: String,
|
||||
role_name_to: String,
|
||||
) -> Self {
|
||||
let request_type = Self::TYPE.to_string();
|
||||
let prd = RequestPrd::new(
|
||||
request_item_name,
|
||||
request_type,
|
||||
request_version,
|
||||
request_process_hash,
|
||||
request_pcd_reference_hash,
|
||||
request_item_reference_hash,
|
||||
pcd_keys_role_confidential_list_enc_by_shared_secret,
|
||||
message_public,
|
||||
message_confidential,
|
||||
message_private,
|
||||
sp_address_to,
|
||||
sp_address_from,
|
||||
sp_address_reply,
|
||||
timestamp_declared,
|
||||
role_name_from,
|
||||
role_name_to,
|
||||
);
|
||||
RequestPrdMessage { prd }
|
||||
}
|
||||
|
||||
pub fn to_message(
|
||||
&self,
|
||||
process_public_enc_key: KeyEncryption,
|
||||
message_shared_peer_list: Vec<SharedPeer>,
|
||||
message_shared_process_list: Vec<SharedProcess>,
|
||||
message_faucet_sp_address: String,
|
||||
pow_pathern: String,
|
||||
pow_difficulty: usize,
|
||||
) -> MessageClient {
|
||||
let mut hasher: DefaultHasher = DefaultHasher::new();
|
||||
self.hash(&mut hasher);
|
||||
let request_hash = hasher.finish().to_string();
|
||||
let request_enc: String = process_public_enc_key
|
||||
.enc_prd_message(self.clone())
|
||||
.to_string();
|
||||
|
||||
MessageClient::new(
|
||||
request_enc,
|
||||
request_hash,
|
||||
message_shared_peer_list,
|
||||
message_shared_process_list,
|
||||
message_faucet_sp_address,
|
||||
pow_pathern,
|
||||
pow_difficulty,
|
||||
)
|
||||
}
|
||||
// Fonction pour afficher ou retourner les informations
|
||||
pub fn display_info(&self) -> String {
|
||||
format!("PRD: {:?}", self.prd)
|
||||
}
|
||||
}
|
181
src/models/request_prd_response.rs
Normal file
181
src/models/request_prd_response.rs
Normal file
@ -0,0 +1,181 @@
|
||||
use rocket::FromForm;
|
||||
use serde_json::json;
|
||||
use std::{collections::hash_map::DefaultHasher, hash::Hash, hash::Hasher};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::workflows::workflow_pcd_create_and_send_all::PcdItemEncAttributeRoleConfidentialExportKey;
|
||||
|
||||
use super::{
|
||||
commitment_method::CommitmentMethod, deposit_method::DepositMethod,
|
||||
key_encryption::KeyEncryption, message_client::MessageClient, payment_method::PaymentMethod,
|
||||
request_prd::RequestPrd, shared_peer::SharedPeer, shared_process::SharedProcess,
|
||||
};
|
||||
#[derive(
|
||||
Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, FromForm, Hash, PartialOrd, Ord,
|
||||
)]
|
||||
|
||||
pub struct RequestPrdResponse {
|
||||
pub prd: RequestPrd,
|
||||
pub sig_value: String,
|
||||
pub pcd_origin_hash: Option<String>,
|
||||
pub payment_method_enc_by_shared_secret: Option<String>,
|
||||
pub deposit_method_enc_by_shared_secret: Option<String>,
|
||||
pub commitment_method_enc_by_shared_secret: Option<String>,
|
||||
pub certif_key_enc_by_shared_secret: Option<String>,
|
||||
pub shared_secret_key: Option<KeyEncryption>,
|
||||
}
|
||||
|
||||
impl RequestPrdResponse {
|
||||
pub const TYPE: &'static str = "prd_response";
|
||||
pub fn new(
|
||||
process_public_enc_key: KeyEncryption,
|
||||
member_private_enc_key: KeyEncryption,
|
||||
|
||||
request_item_name: Option<String>,
|
||||
request_version: i64,
|
||||
request_process_hash: String,
|
||||
request_pcd_reference_hash: Option<String>,
|
||||
request_item_reference_hash: Option<String>,
|
||||
pcd_keys_role_confidential_list: Vec<PcdItemEncAttributeRoleConfidentialExportKey>,
|
||||
|
||||
message_public_string: Option<String>,
|
||||
message_confidential_string: Option<String>,
|
||||
message_private_string: Option<String>,
|
||||
|
||||
sp_address_to: String,
|
||||
sp_address_from: String,
|
||||
sp_address_reply: String,
|
||||
timestamp_declared: u64,
|
||||
role_name_from: String,
|
||||
role_name_to: String,
|
||||
|
||||
sig_value: String,
|
||||
pcd_origin_hash: Option<String>,
|
||||
|
||||
payment_method: Option<PaymentMethod>,
|
||||
deposit_method: Option<DepositMethod>,
|
||||
commitment_method: Option<CommitmentMethod>,
|
||||
certif_key: Option<String>,
|
||||
) -> Self {
|
||||
let mut shared_secret_key =
|
||||
KeyEncryption::new(Some("secret_shared".to_owned()), None, None);
|
||||
|
||||
if let Ok(_new) = shared_secret_key.key_new_random() {
|
||||
let payment_method_enc_by_shared_secret = match payment_method {
|
||||
Some(ref _msg) => {
|
||||
Some(shared_secret_key.enc(serde_json::to_value(payment_method).unwrap()))
|
||||
}
|
||||
None => None,
|
||||
};
|
||||
|
||||
let deposit_method_enc_by_shared_secret = match deposit_method {
|
||||
Some(ref _msg) => {
|
||||
Some(shared_secret_key.enc(serde_json::to_value(deposit_method).unwrap()))
|
||||
}
|
||||
None => None,
|
||||
};
|
||||
|
||||
let commitment_method_enc_by_shared_secret = match commitment_method {
|
||||
Some(ref _msg) => {
|
||||
Some(shared_secret_key.enc(serde_json::to_value(commitment_method).unwrap()))
|
||||
}
|
||||
None => None,
|
||||
};
|
||||
|
||||
let certif_key_enc_by_shared_secret = match certif_key {
|
||||
Some(ref _msg) => {
|
||||
Some(shared_secret_key.enc(serde_json::to_value(certif_key).unwrap()))
|
||||
}
|
||||
None => None,
|
||||
};
|
||||
|
||||
let message_confidential = message_confidential_string
|
||||
.as_ref()
|
||||
.map(|msg| shared_secret_key.enc_string(msg.clone()));
|
||||
let message_public = message_public_string
|
||||
.as_ref()
|
||||
.map(|msg| process_public_enc_key.enc_string(msg.clone()));
|
||||
let message_private = message_private_string
|
||||
.as_ref()
|
||||
.map(|msg| member_private_enc_key.enc_string(msg.clone()));
|
||||
|
||||
let pcd_keys_role_confidential_list_enc_by_shared_secret = shared_secret_key.enc(
|
||||
serde_json::to_value(pcd_keys_role_confidential_list).unwrap_or_else(|_| json!({})),
|
||||
);
|
||||
|
||||
let request_type = Self::TYPE.to_string();
|
||||
let prd = RequestPrd::new(
|
||||
request_item_name,
|
||||
request_type,
|
||||
request_version,
|
||||
request_process_hash,
|
||||
request_pcd_reference_hash,
|
||||
request_item_reference_hash,
|
||||
pcd_keys_role_confidential_list_enc_by_shared_secret,
|
||||
message_public,
|
||||
message_confidential,
|
||||
message_private,
|
||||
sp_address_to,
|
||||
sp_address_from,
|
||||
sp_address_reply,
|
||||
timestamp_declared,
|
||||
role_name_from,
|
||||
role_name_to,
|
||||
);
|
||||
RequestPrdResponse {
|
||||
prd,
|
||||
sig_value,
|
||||
pcd_origin_hash,
|
||||
payment_method_enc_by_shared_secret,
|
||||
deposit_method_enc_by_shared_secret,
|
||||
commitment_method_enc_by_shared_secret,
|
||||
certif_key_enc_by_shared_secret,
|
||||
shared_secret_key: Some(shared_secret_key),
|
||||
}
|
||||
} else {
|
||||
panic!("Error: Could not create shared secret key");
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_message(
|
||||
&self,
|
||||
process_public_enc_key: KeyEncryption,
|
||||
message_shared_peer_list: Vec<SharedPeer>,
|
||||
message_shared_process_list: Vec<SharedProcess>,
|
||||
message_faucet_sp_address: String,
|
||||
pow_pathern: String,
|
||||
pow_difficulty: usize,
|
||||
) -> MessageClient {
|
||||
let mut hasher: DefaultHasher = DefaultHasher::new();
|
||||
self.hash(&mut hasher);
|
||||
let request_hash = hasher.finish().to_string();
|
||||
let request_enc: String = process_public_enc_key
|
||||
.enc_prd_response(self.clone())
|
||||
.to_string();
|
||||
|
||||
MessageClient::new(
|
||||
request_enc,
|
||||
request_hash,
|
||||
message_shared_peer_list,
|
||||
message_shared_process_list,
|
||||
message_faucet_sp_address,
|
||||
pow_pathern,
|
||||
pow_difficulty,
|
||||
)
|
||||
}
|
||||
|
||||
// Fonction pour afficher ou retourner les informations
|
||||
pub fn display_info(&self) -> String {
|
||||
format!(
|
||||
"PRD: {:?}, Sig Value: {}, PCD Origin Hash: {}, Payment Method Encrypted: {}, Deposit Method Encrypted: {}, Commitment Method Encrypted: {}, Certification Key Encrypted: {}",
|
||||
self.prd,
|
||||
self.sig_value,
|
||||
self.pcd_origin_hash.as_ref().unwrap(),
|
||||
self.payment_method_enc_by_shared_secret.as_ref().unwrap(),
|
||||
self.deposit_method_enc_by_shared_secret.as_ref().unwrap(),
|
||||
self.commitment_method_enc_by_shared_secret.as_ref().unwrap(),
|
||||
self.certif_key_enc_by_shared_secret.as_ref().unwrap()
|
||||
)
|
||||
}
|
||||
}
|
130
src/models/request_prd_update.rs
Normal file
130
src/models/request_prd_update.rs
Normal file
@ -0,0 +1,130 @@
|
||||
use rocket::FromForm;
|
||||
use std::{
|
||||
collections::hash_map::DefaultHasher,
|
||||
hash::{Hash, Hasher},
|
||||
};
|
||||
|
||||
use super::{
|
||||
key_encryption::KeyEncryption, message_client::MessageClient, request_prd::RequestPrd,
|
||||
shared_peer::SharedPeer, shared_process::SharedProcess,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
#[derive(
|
||||
Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, FromForm,
|
||||
)]
|
||||
|
||||
pub struct RequestPrdUpdate {
|
||||
pub prd: RequestPrd,
|
||||
pub pcd_new_version_hash: String,
|
||||
pub payment_pcd_hash_list: Vec<String>,
|
||||
pub cap_pcd_hash_list: Vec<String>,
|
||||
pub deposit_pcd_hash_list: Vec<String>,
|
||||
pub commitment_pcd_hash_list: Vec<String>,
|
||||
pub ask_payment_method: String,
|
||||
pub ask_deposit_method: String,
|
||||
pub ask_commitment_method: String,
|
||||
}
|
||||
|
||||
impl RequestPrdUpdate {
|
||||
pub const TYPE: &'static str = "prd_update";
|
||||
pub fn new(
|
||||
request_item_name: Option<String>,
|
||||
request_version: i64,
|
||||
request_process_hash: String,
|
||||
request_pcd_reference_hash: Option<String>,
|
||||
request_item_reference_hash: Option<String>,
|
||||
pcd_keys_role_confidential_list_enc_by_shared_secret: String,
|
||||
message_public: Option<String>,
|
||||
message_confidential: Option<String>,
|
||||
message_private: Option<String>,
|
||||
sp_address_to: String,
|
||||
sp_address_from: String,
|
||||
sp_address_reply: String,
|
||||
timestamp_declared: u64,
|
||||
role_name_from: String,
|
||||
role_name_to: String,
|
||||
|
||||
pcd_new_version_hash: String,
|
||||
payment_pcd_hash_list: Vec<String>,
|
||||
cap_pcd_hash_list: Vec<String>,
|
||||
deposit_pcd_hash_list: Vec<String>,
|
||||
commitment_pcd_hash_list: Vec<String>,
|
||||
ask_payment_method: String,
|
||||
ask_deposit_method: String,
|
||||
ask_commitment_method: String,
|
||||
) -> Self {
|
||||
let request_type = Self::TYPE.to_string();
|
||||
let prd = RequestPrd::new(
|
||||
request_item_name,
|
||||
request_type,
|
||||
request_version,
|
||||
request_process_hash,
|
||||
request_pcd_reference_hash,
|
||||
request_item_reference_hash,
|
||||
pcd_keys_role_confidential_list_enc_by_shared_secret,
|
||||
message_public,
|
||||
message_confidential,
|
||||
message_private,
|
||||
sp_address_to,
|
||||
sp_address_from,
|
||||
sp_address_reply,
|
||||
timestamp_declared,
|
||||
role_name_from,
|
||||
role_name_to,
|
||||
);
|
||||
RequestPrdUpdate {
|
||||
prd,
|
||||
pcd_new_version_hash,
|
||||
payment_pcd_hash_list,
|
||||
cap_pcd_hash_list,
|
||||
deposit_pcd_hash_list,
|
||||
commitment_pcd_hash_list,
|
||||
ask_payment_method,
|
||||
ask_deposit_method,
|
||||
ask_commitment_method,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_message(
|
||||
&self,
|
||||
process_public_enc_key: KeyEncryption,
|
||||
message_shared_peer_list: Vec<SharedPeer>,
|
||||
message_shared_process_list: Vec<SharedProcess>,
|
||||
message_faucet_sp_address: String,
|
||||
pow_pathern: String,
|
||||
pow_difficulty: usize,
|
||||
) -> MessageClient {
|
||||
let mut hasher: DefaultHasher = DefaultHasher::new();
|
||||
self.hash(&mut hasher);
|
||||
let request_hash = hasher.finish().to_string();
|
||||
let request_enc: String = process_public_enc_key
|
||||
.enc_prd_update(self.clone())
|
||||
.to_string();
|
||||
|
||||
MessageClient::new(
|
||||
request_enc,
|
||||
request_hash,
|
||||
message_shared_peer_list,
|
||||
message_shared_process_list,
|
||||
message_faucet_sp_address,
|
||||
pow_pathern,
|
||||
pow_difficulty,
|
||||
)
|
||||
}
|
||||
|
||||
// Fonction pour afficher ou retourner les informations
|
||||
pub fn display_info(&self) -> String {
|
||||
format!(
|
||||
"PRD: {:?}, PCD New Version Hash: {}, Payment PCD Hash List: {:?}, Cap PCD Hash List: {:?}, Deposit PCD Hash List: {:?}, Commitment PCD Hash List: {:?}, Ask Payment Method: {}, Ask Deposit Method: {}, Ask Commitment Method: {}",
|
||||
self.prd,
|
||||
self.pcd_new_version_hash,
|
||||
self.payment_pcd_hash_list,
|
||||
self.cap_pcd_hash_list,
|
||||
self.deposit_pcd_hash_list,
|
||||
self.commitment_pcd_hash_list,
|
||||
self.ask_payment_method,
|
||||
self.ask_deposit_method,
|
||||
self.ask_commitment_method,
|
||||
)
|
||||
}
|
||||
}
|
210
src/models/role.rs
Normal file
210
src/models/role.rs
Normal file
@ -0,0 +1,210 @@
|
||||
use rocket::FromForm;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::{
|
||||
condition_cap::ConditionCap, condition_commitment::ConditionCommitment,
|
||||
condition_orchestration::ConditionOrchestration, condition_payment::ConditionPayment,
|
||||
condition_prd_address_set::ConditionPrdAddressSet, condition_publish::ConditionPublish,
|
||||
item::Item, metadata::Amount,
|
||||
};
|
||||
#[derive(
|
||||
Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, FromForm,
|
||||
)]
|
||||
|
||||
pub struct TransactionModeDistribution {
|
||||
pub from_prd_update_from: String,
|
||||
pub from_role_list: Vec<String>,
|
||||
pub to_role_list: Vec<String>,
|
||||
pub from_prd_address_list: Vec<String>,
|
||||
pub to_prd_address_list: Vec<String>,
|
||||
pub method: String,
|
||||
}
|
||||
|
||||
impl TransactionModeDistribution {
|
||||
pub fn new(
|
||||
from_prd_update_from: String,
|
||||
from_role_list: Vec<String>,
|
||||
to_role_list: Vec<String>,
|
||||
from_prd_address_list: Vec<String>,
|
||||
to_prd_address_list: Vec<String>,
|
||||
method: String,
|
||||
) -> Self {
|
||||
TransactionModeDistribution {
|
||||
from_prd_update_from,
|
||||
from_role_list,
|
||||
to_role_list,
|
||||
from_prd_address_list,
|
||||
to_prd_address_list,
|
||||
method,
|
||||
}
|
||||
}
|
||||
// display_info method
|
||||
pub fn display_info(&self) {
|
||||
println!("TransactionModeDistribution:");
|
||||
println!("From PRD Update From: {}", self.from_prd_update_from);
|
||||
println!("From Role List: {:?}", self.from_role_list);
|
||||
println!("To Role List: {:?}", self.to_role_list);
|
||||
println!("From PRD Address List: {:?}", self.from_prd_address_list);
|
||||
println!("To PRD Address List: {:?}", self.to_prd_address_list);
|
||||
println!("Method: {}", self.method);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(
|
||||
Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, FromForm,
|
||||
)]
|
||||
|
||||
pub struct TransactionModeDirect {
|
||||
pub from_prd_update_from: String,
|
||||
pub to_role_owner: String,
|
||||
}
|
||||
|
||||
impl TransactionModeDirect {
|
||||
pub fn new(from_prd_update_from: String, to_role_owner: String) -> Self {
|
||||
TransactionModeDirect {
|
||||
from_prd_update_from,
|
||||
to_role_owner,
|
||||
}
|
||||
}
|
||||
|
||||
// display_info method
|
||||
pub fn display_info(&self) {
|
||||
println!("TransactionModeDirect:");
|
||||
println!("From PRD Update From: {}", self.from_prd_update_from);
|
||||
println!("To Role Owner: {}", self.to_role_owner);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(
|
||||
Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, FromForm,
|
||||
)]
|
||||
pub struct TransactionMode {
|
||||
pub amount: Amount,
|
||||
pub role_transaction_distribution: TransactionModeDistribution,
|
||||
pub role_transaction_direct: TransactionModeDirect,
|
||||
}
|
||||
|
||||
impl TransactionMode {
|
||||
pub fn new(
|
||||
amount: Amount,
|
||||
role_transaction_distribution: TransactionModeDistribution,
|
||||
role_transaction_direct: TransactionModeDirect,
|
||||
) -> Self {
|
||||
TransactionMode {
|
||||
amount,
|
||||
role_transaction_distribution,
|
||||
role_transaction_direct,
|
||||
}
|
||||
}
|
||||
|
||||
// display_info method
|
||||
pub fn display_info(&self) {
|
||||
println!("TransactionMode:");
|
||||
|
||||
println!("Amount:");
|
||||
self.amount.display_info(); // Assuming Amount has a display_info method
|
||||
|
||||
println!("Role Transaction Distribution:");
|
||||
self.role_transaction_distribution.display_info(); // Assuming TransactionModeDistribution has a display_info method
|
||||
|
||||
println!("Role Transaction Direct:");
|
||||
self.role_transaction_direct.display_info(); // Assuming TransactionModeDirect has a display_info method
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(
|
||||
Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, FromForm,
|
||||
)]
|
||||
|
||||
pub struct Role {
|
||||
pub item: Item,
|
||||
pub required_2fa: bool,
|
||||
pub validation_timeout: u64,
|
||||
pub condition_prd_address_set_list: Vec<ConditionPrdAddressSet>, // Assuming ConditionPrdAddressSet is a predefined struct
|
||||
pub condition_publish: ConditionPublish, // Assuming ConditionPublish is a predefined struct
|
||||
pub condition_cap_list: Vec<ConditionCap>, // Assuming ConditionCap is a predefined struct
|
||||
pub condition_payment_list: Vec<ConditionPayment>, // Assuming ConditionPayment is a predefined struct
|
||||
pub condition_commitment_list: Vec<ConditionCommitment>, // Assuming ConditionCommitment is a predefined struct
|
||||
pub condition_attribute_encryption_list: Vec<String>,
|
||||
pub condition_orchestration: ConditionOrchestration, // Assuming ConditionOrchestration is a predefined struct
|
||||
pub role_succession: Option<String>,
|
||||
pub role_resolve: Option<String>,
|
||||
pub role_renew: Option<String>,
|
||||
}
|
||||
|
||||
impl Role {
|
||||
pub fn new(
|
||||
item: Item,
|
||||
required_2fa: bool,
|
||||
validation_timeout: u64,
|
||||
condition_prd_address_set_list: Vec<ConditionPrdAddressSet>,
|
||||
condition_publish: ConditionPublish,
|
||||
condition_cap_list: Vec<ConditionCap>,
|
||||
condition_payment_list: Vec<ConditionPayment>,
|
||||
condition_commitment_list: Vec<ConditionCommitment>,
|
||||
condition_attribute_encryption_list: Vec<String>,
|
||||
condition_orchestration: ConditionOrchestration,
|
||||
role_succession: Option<String>,
|
||||
role_resolve: Option<String>,
|
||||
role_renew: Option<String>,
|
||||
) -> Self {
|
||||
Role {
|
||||
item,
|
||||
required_2fa,
|
||||
validation_timeout,
|
||||
condition_prd_address_set_list,
|
||||
condition_publish,
|
||||
condition_cap_list,
|
||||
condition_payment_list,
|
||||
condition_commitment_list,
|
||||
condition_attribute_encryption_list,
|
||||
condition_orchestration,
|
||||
role_succession,
|
||||
role_resolve,
|
||||
role_renew,
|
||||
}
|
||||
}
|
||||
// display_info method
|
||||
pub fn display_info(&self) {
|
||||
println!("Role:");
|
||||
println!("Item: {:?}", self.item); // Assuming `Item` implements Debug trait
|
||||
println!("Validation Timeout: {}", self.validation_timeout);
|
||||
|
||||
println!("ConditionPrdAddressSet List:");
|
||||
for condition in &self.condition_prd_address_set_list {
|
||||
condition.display_info(); // Assuming `ConditionPrdAddressSet` has a display_info method
|
||||
}
|
||||
|
||||
println!("ConditionPublish:");
|
||||
self.condition_publish.display_info(); // Assuming `ConditionPublish` has a display_info method
|
||||
|
||||
println!("ConditionCap List:");
|
||||
for condition in &self.condition_cap_list {
|
||||
condition.display_info(); // Assuming `ConditionCap` has a display_info method
|
||||
}
|
||||
|
||||
println!("ConditionPayment List:");
|
||||
for condition in &self.condition_payment_list {
|
||||
condition.display_info(); // Assuming `ConditionPayment` has a display_info method
|
||||
}
|
||||
|
||||
println!("ConditionCommitment List:");
|
||||
for condition in &self.condition_commitment_list {
|
||||
condition.display_info(); // Assuming `ConditionCommitment` has a display_info method
|
||||
}
|
||||
|
||||
println!("ConditionAttributeEncryption:");
|
||||
for condition in &self.condition_attribute_encryption_list {
|
||||
println!("ConditionAttributeEncryption: {:?}", condition);
|
||||
}
|
||||
|
||||
println!("ConditionOrchestration:");
|
||||
self.condition_orchestration.display_info(); // Assuming `ConditionOrchestration` has a display_info method
|
||||
|
||||
println!("Role Succession: {:?}", self.role_succession);
|
||||
println!("Role Resolve: {:?}", self.role_resolve);
|
||||
println!("Role Renew: {:?}", self.role_renew);
|
||||
}
|
||||
|
||||
// Additional methods for Role can be added here
|
||||
}
|
23
src/models/role_artefact.rs
Normal file
23
src/models/role_artefact.rs
Normal file
@ -0,0 +1,23 @@
|
||||
use rocket::FromForm;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::role::Role;
|
||||
#[derive(
|
||||
Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, FromForm,
|
||||
)]
|
||||
|
||||
pub struct RoleArtefact {
|
||||
pub item_name: String,
|
||||
pub role: Role,
|
||||
}
|
||||
|
||||
impl RoleArtefact {
|
||||
pub fn new(item_name: String, role: Role) -> Self {
|
||||
RoleArtefact { item_name, role }
|
||||
}
|
||||
|
||||
// Fonction pour afficher ou retourner les informations
|
||||
pub fn display_info(&self) -> String {
|
||||
format!("Item Name: {}, Role: {:?}", self.item_name, self.role)
|
||||
}
|
||||
}
|
23
src/models/role_commitment.rs
Normal file
23
src/models/role_commitment.rs
Normal file
@ -0,0 +1,23 @@
|
||||
use rocket::FromForm;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::role::Role;
|
||||
#[derive(
|
||||
Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, FromForm,
|
||||
)]
|
||||
|
||||
pub struct RoleCommitment {
|
||||
pub item_name: String,
|
||||
pub role: Role,
|
||||
}
|
||||
|
||||
impl RoleCommitment {
|
||||
pub fn new(item_name: String, role: Role) -> Self {
|
||||
RoleCommitment { item_name, role }
|
||||
}
|
||||
|
||||
// Fonction pour afficher ou retourner les informations
|
||||
pub fn display_info(&self) -> String {
|
||||
format!("Item Name: {}, Role: {:?}", self.item_name, self.role)
|
||||
}
|
||||
}
|
23
src/models/role_deposit.rs
Normal file
23
src/models/role_deposit.rs
Normal file
@ -0,0 +1,23 @@
|
||||
use rocket::FromForm;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::role::Role;
|
||||
#[derive(
|
||||
Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, FromForm,
|
||||
)]
|
||||
|
||||
pub struct RoleDeposit {
|
||||
pub item_name: String,
|
||||
pub role: Role,
|
||||
}
|
||||
|
||||
impl RoleDeposit {
|
||||
pub fn new(item_name: String, role: Role) -> Self {
|
||||
RoleDeposit { item_name, role }
|
||||
}
|
||||
|
||||
// Fonction pour afficher ou retourner les informations
|
||||
pub fn display_info(&self) -> String {
|
||||
format!("Item Name: {}, Role: {:?}", self.item_name, self.role)
|
||||
}
|
||||
}
|
21
src/models/role_member.rs
Normal file
21
src/models/role_member.rs
Normal file
@ -0,0 +1,21 @@
|
||||
use rocket::FromForm;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::role::Role;
|
||||
#[derive(
|
||||
Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, FromForm,
|
||||
)]
|
||||
|
||||
pub struct RoleMember {
|
||||
pub item_name: String,
|
||||
pub role: Role,
|
||||
}
|
||||
|
||||
impl RoleMember {
|
||||
pub fn new(item_name: String, role: Role) -> Self {
|
||||
RoleMember { item_name, role }
|
||||
}
|
||||
pub fn display_info(&self) -> String {
|
||||
format!("Item Name: {}, Role: {:?}", self.item_name, self.role)
|
||||
}
|
||||
}
|
23
src/models/role_payment.rs
Normal file
23
src/models/role_payment.rs
Normal file
@ -0,0 +1,23 @@
|
||||
use rocket::FromForm;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::role::Role;
|
||||
#[derive(
|
||||
Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, FromForm,
|
||||
)]
|
||||
|
||||
pub struct RolePayment {
|
||||
pub item_name: String,
|
||||
pub role: Role,
|
||||
}
|
||||
|
||||
impl RolePayment {
|
||||
pub fn new(item_name: String, role: Role) -> Self {
|
||||
RolePayment { item_name, role }
|
||||
}
|
||||
|
||||
// Fonction pour afficher ou retourner les informations
|
||||
pub fn display_info(&self) -> String {
|
||||
format!("Item Name: {}, Role: {:?}", self.item_name, self.role)
|
||||
}
|
||||
}
|
23
src/models/role_peer.rs
Normal file
23
src/models/role_peer.rs
Normal file
@ -0,0 +1,23 @@
|
||||
use rocket::FromForm;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::role::Role;
|
||||
#[derive(
|
||||
Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, FromForm,
|
||||
)]
|
||||
|
||||
pub struct RolePeer {
|
||||
pub item_name: String,
|
||||
pub role: Role,
|
||||
}
|
||||
|
||||
impl RolePeer {
|
||||
pub fn new(item_name: String, role: Role) -> Self {
|
||||
RolePeer { item_name, role }
|
||||
}
|
||||
|
||||
// Fonction pour afficher ou retourner les informations
|
||||
pub fn display_info(&self) -> String {
|
||||
format!("Item Name: {}, Role: {:?}", self.item_name, self.role)
|
||||
}
|
||||
}
|
21
src/models/role_process.rs
Normal file
21
src/models/role_process.rs
Normal file
@ -0,0 +1,21 @@
|
||||
use rocket::FromForm;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::role::Role;
|
||||
#[derive(
|
||||
Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, FromForm,
|
||||
)]
|
||||
|
||||
pub struct RoleProcess {
|
||||
pub item_name: String,
|
||||
pub role: Role,
|
||||
}
|
||||
|
||||
impl RoleProcess {
|
||||
pub fn new(item_name: String, role: Role) -> Self {
|
||||
RoleProcess { item_name, role }
|
||||
}
|
||||
pub fn display_info(&self) -> String {
|
||||
format!("Item Name: {}, Role: {:?}", self.item_name, self.role)
|
||||
}
|
||||
}
|
132
src/models/roles_group.rs
Normal file
132
src/models/roles_group.rs
Normal file
@ -0,0 +1,132 @@
|
||||
use rocket::FromForm;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::workflows::workflow_pcd_create_and_send_all::PcdItemEncAttributeRoleConfidentialExportKey;
|
||||
|
||||
use super::{
|
||||
commitment_method::CommitmentMethod, deposit_method::DepositMethod,
|
||||
key_encryption::KeyEncryption, payment_method::PaymentMethod,
|
||||
request_prd_response::RequestPrdResponse, role_artefact::RoleArtefact, role_member::RoleMember,
|
||||
role_peer::RolePeer, role_process::RoleProcess,
|
||||
};
|
||||
|
||||
#[derive(
|
||||
Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, FromForm,
|
||||
)]
|
||||
|
||||
pub struct RolesGroup {
|
||||
pub role_peer: RolePeer,
|
||||
pub role_member: RoleMember,
|
||||
pub role_process: RoleProcess,
|
||||
pub role_artefact_list: Vec<RoleArtefact>,
|
||||
}
|
||||
|
||||
impl RolesGroup {
|
||||
pub fn new(
|
||||
role_peer: RolePeer,
|
||||
role_member: RoleMember,
|
||||
role_process: RoleProcess,
|
||||
role_artefact_list: Vec<RoleArtefact>,
|
||||
) -> Self {
|
||||
RolesGroup {
|
||||
role_peer,
|
||||
role_member,
|
||||
role_process,
|
||||
role_artefact_list,
|
||||
}
|
||||
}
|
||||
pub fn filter_keys(
|
||||
condition_attribute_encryption: &Vec<String>,
|
||||
pcd_keys_role_confidential_list: &mut Vec<PcdItemEncAttributeRoleConfidentialExportKey>,
|
||||
) {
|
||||
for key_item in pcd_keys_role_confidential_list.iter_mut() {
|
||||
if !condition_attribute_encryption.contains(&key_item.attribute_name) {
|
||||
key_item.key = None;
|
||||
}
|
||||
}
|
||||
}
|
||||
pub fn to_prd_response_list(
|
||||
&self,
|
||||
process_public_enc_key: KeyEncryption,
|
||||
member_private_enc_key: KeyEncryption,
|
||||
request_item_name: Option<String>,
|
||||
request_version: i64,
|
||||
request_process_hash: String,
|
||||
request_pcd_reference_hash: Option<String>,
|
||||
request_item_reference_hash: Option<String>,
|
||||
pcd_keys_role_confidential_list: Vec<PcdItemEncAttributeRoleConfidentialExportKey>,
|
||||
message_public_string: Option<String>,
|
||||
message_confidential_string: Option<String>,
|
||||
message_private_string: Option<String>,
|
||||
sp_address_from: String,
|
||||
sp_address_reply: String,
|
||||
timestamp_declared: u64,
|
||||
role_name_from: String,
|
||||
role_name_to: String,
|
||||
sig_value: String,
|
||||
pcd_origin_hash: Option<String>,
|
||||
|
||||
payment_method: Option<PaymentMethod>,
|
||||
deposit_method: Option<DepositMethod>,
|
||||
commitment_method: Option<CommitmentMethod>,
|
||||
certif_key: Option<String>,
|
||||
) -> Vec<RequestPrdResponse> {
|
||||
let mut request_prd_response_list: Vec<RequestPrdResponse> = Vec::new();
|
||||
|
||||
for cond in &self.role_peer.role.condition_prd_address_set_list {
|
||||
let mut pcd_keys_role_confidential_list_tmp = pcd_keys_role_confidential_list.clone();
|
||||
|
||||
RolesGroup::filter_keys(
|
||||
&self.role_peer.role.condition_attribute_encryption_list,
|
||||
&mut pcd_keys_role_confidential_list_tmp,
|
||||
);
|
||||
|
||||
for address in &cond.prd_sp_address_list {
|
||||
let prd_response = RequestPrdResponse::new(
|
||||
process_public_enc_key.clone(),
|
||||
member_private_enc_key.clone(),
|
||||
request_item_name.clone(),
|
||||
request_version.clone(),
|
||||
request_process_hash.clone(),
|
||||
request_pcd_reference_hash.clone(),
|
||||
request_item_reference_hash.clone(),
|
||||
pcd_keys_role_confidential_list.clone(),
|
||||
message_public_string.clone(),
|
||||
message_confidential_string.clone(),
|
||||
message_private_string.clone(),
|
||||
address.to_string(),
|
||||
sp_address_from.clone(),
|
||||
sp_address_reply.clone(),
|
||||
timestamp_declared.clone(),
|
||||
role_name_from.clone(),
|
||||
role_name_to.clone(),
|
||||
sig_value.clone(),
|
||||
pcd_origin_hash.clone(),
|
||||
payment_method.clone(),
|
||||
deposit_method.clone(),
|
||||
commitment_method.clone(),
|
||||
certif_key.clone(),
|
||||
);
|
||||
request_prd_response_list.push(prd_response);
|
||||
}
|
||||
}
|
||||
request_prd_response_list
|
||||
}
|
||||
pub fn display_info(&self) {
|
||||
println!("RolesGroup:");
|
||||
println!("Role Peer:");
|
||||
self.role_peer.display_info(); // Affiche les informations de `role_peer`
|
||||
|
||||
println!("Role Member:");
|
||||
self.role_member.display_info(); // Affiche les informations de `role_member`
|
||||
|
||||
println!("Role Process:");
|
||||
self.role_process.display_info(); // Affiche les informations de `role_process`
|
||||
|
||||
println!("Role Artefact List:");
|
||||
for (index, role_artefact) in self.role_artefact_list.iter().enumerate() {
|
||||
println!("Artefact {}: ", index + 1);
|
||||
role_artefact.display_info(); // Affiche les informations de chaque `role_artefact`
|
||||
}
|
||||
}
|
||||
}
|
226
src/models/shared_peer.rs
Normal file
226
src/models/shared_peer.rs
Normal file
@ -0,0 +1,226 @@
|
||||
use rocket::FromForm;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::message_client::MessageClient;
|
||||
#[derive(
|
||||
Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, FromForm,
|
||||
)]
|
||||
|
||||
pub struct Relay {
|
||||
pub address_port: u16,
|
||||
pub data_max_size: usize,
|
||||
pub pow_difficulty: u32,
|
||||
pub pow_pattern: String,
|
||||
pub pow_prefix: String,
|
||||
}
|
||||
|
||||
impl Relay {
|
||||
pub fn new(
|
||||
address_port: u16,
|
||||
data_max_size: usize,
|
||||
pow_difficulty: u32,
|
||||
pow_pattern: String,
|
||||
pow_prefix: String,
|
||||
) -> Self {
|
||||
Relay {
|
||||
address_port,
|
||||
data_max_size,
|
||||
pow_difficulty,
|
||||
pow_pattern,
|
||||
pow_prefix,
|
||||
}
|
||||
}
|
||||
// display_info method
|
||||
pub fn display_info(&self) {
|
||||
println!("Relay:");
|
||||
println!("Address Port: {}", self.address_port);
|
||||
println!("Data Max Size: {}", self.data_max_size);
|
||||
println!("PoW Difficulty: {}", self.pow_difficulty);
|
||||
println!("PoW Pattern: {}", self.pow_pattern);
|
||||
println!("PoW Prefix: {}", self.pow_prefix);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(
|
||||
Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, FromForm,
|
||||
)]
|
||||
|
||||
pub struct L1Node {
|
||||
pub address_port: u16,
|
||||
pub explorer_base_url: String,
|
||||
pub sp_address_anchorage: String,
|
||||
pub sp_address_reward: String,
|
||||
}
|
||||
|
||||
impl L1Node {
|
||||
pub fn new(
|
||||
address_port: u16,
|
||||
explorer_base_url: String,
|
||||
sp_address_anchorage: String,
|
||||
sp_address_reward: String,
|
||||
) -> Self {
|
||||
L1Node {
|
||||
address_port,
|
||||
explorer_base_url,
|
||||
sp_address_anchorage,
|
||||
sp_address_reward,
|
||||
}
|
||||
} // display_info method
|
||||
pub fn display_info(&self) {
|
||||
println!("L1Node:");
|
||||
println!("Address Port: {}", self.address_port);
|
||||
println!("Explorer Base URL: {}", self.explorer_base_url);
|
||||
println!("SP Address Anchorage: {}", self.sp_address_anchorage);
|
||||
println!("SP Address Reward: {}", self.sp_address_reward);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(
|
||||
Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, FromForm,
|
||||
)]
|
||||
|
||||
pub struct L1Miner {
|
||||
pub sp_address_rewarder: String,
|
||||
}
|
||||
|
||||
impl L1Miner {
|
||||
pub fn new(sp_address_rewarder: String) -> Self {
|
||||
L1Miner {
|
||||
sp_address_rewarder,
|
||||
}
|
||||
}
|
||||
|
||||
// display_info method
|
||||
pub fn display_info(&self) {
|
||||
println!("L1Miner:");
|
||||
println!("SP Address Rewarder: {}", self.sp_address_rewarder);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(
|
||||
Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, FromForm,
|
||||
)]
|
||||
|
||||
pub struct L2Node {
|
||||
pub address_port: u16,
|
||||
pub explorer_base_url: String,
|
||||
pub sp_address_anchorage: String,
|
||||
pub sp_address_reward: String,
|
||||
pub nbits: u32,
|
||||
pub magic_number: u32,
|
||||
pub challenge: String,
|
||||
}
|
||||
|
||||
impl L2Node {
|
||||
pub fn new(
|
||||
address_port: u16,
|
||||
explorer_base_url: String,
|
||||
sp_address_anchorage: String,
|
||||
sp_address_reward: String,
|
||||
nbits: u32,
|
||||
magic_number: u32,
|
||||
challenge: String,
|
||||
) -> Self {
|
||||
L2Node {
|
||||
address_port,
|
||||
explorer_base_url,
|
||||
sp_address_anchorage,
|
||||
sp_address_reward,
|
||||
nbits,
|
||||
magic_number,
|
||||
challenge,
|
||||
}
|
||||
}
|
||||
|
||||
// display_info method
|
||||
pub fn display_info(&self) {
|
||||
println!("L2Node:");
|
||||
println!("Address Port: {}", self.address_port);
|
||||
println!("Explorer Base URL: {}", self.explorer_base_url);
|
||||
println!("SP Address Anchorage: {}", self.sp_address_anchorage);
|
||||
println!("SP Address Reward: {}", self.sp_address_reward);
|
||||
println!("Nbits: {}", self.nbits);
|
||||
println!("Magic Number: {}", self.magic_number);
|
||||
println!("Challenge: {}", self.challenge);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(
|
||||
Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, FromForm,
|
||||
)]
|
||||
|
||||
pub struct L2Certif {
|
||||
pub sp_address_certif: String,
|
||||
}
|
||||
|
||||
impl L2Certif {
|
||||
pub fn new(sp_address_certif: String) -> Self {
|
||||
L2Certif { sp_address_certif }
|
||||
}
|
||||
// display_info method
|
||||
pub fn display_info(&self) {
|
||||
println!("L2Certif:");
|
||||
println!("SP Address Certif: {}", self.sp_address_certif);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(
|
||||
Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, FromForm,
|
||||
)]
|
||||
|
||||
pub struct SharedPeer {
|
||||
pub domain: String,
|
||||
pub address_ip: String,
|
||||
pub relay: Relay,
|
||||
pub l1_node: L1Node,
|
||||
pub l1_miner: L1Miner,
|
||||
pub l2_node: L2Node,
|
||||
pub l2_certif: L2Certif,
|
||||
}
|
||||
|
||||
impl SharedPeer {
|
||||
pub fn new(
|
||||
domain: String,
|
||||
address_ip: String,
|
||||
relay: Relay,
|
||||
l1_node: L1Node,
|
||||
l1_miner: L1Miner,
|
||||
l2_node: L2Node,
|
||||
l2_certif: L2Certif,
|
||||
) -> Self {
|
||||
SharedPeer {
|
||||
domain,
|
||||
address_ip,
|
||||
relay,
|
||||
l1_node,
|
||||
l1_miner,
|
||||
l2_node,
|
||||
l2_certif,
|
||||
}
|
||||
}
|
||||
pub fn send_message_client(&self, _message_client: MessageClient) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
// display_info method
|
||||
pub fn display_info(&self) {
|
||||
println!("SharedPeer:");
|
||||
println!("Domain: {}", self.domain);
|
||||
println!("IP Address: {}", self.address_ip);
|
||||
|
||||
println!("Relay:");
|
||||
self.relay.display_info(); // Assuming Relay has a display_info method
|
||||
|
||||
println!("L1 Node:");
|
||||
self.l1_node.display_info(); // Assuming L1Node has a display_info method
|
||||
|
||||
println!("L1 Miner:");
|
||||
self.l1_miner.display_info(); // Assuming L1Miner has a display_info method
|
||||
|
||||
println!("L2 Node:");
|
||||
self.l2_node.display_info(); // Assuming L2Node has a display_info method
|
||||
|
||||
println!("L2 Certif:");
|
||||
self.l2_certif.display_info(); // Assuming L2Certif has a display_info method
|
||||
}
|
||||
}
|
38
src/models/shared_process.rs
Normal file
38
src/models/shared_process.rs
Normal file
@ -0,0 +1,38 @@
|
||||
use rocket::FromForm;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::key_encryption::KeyEncryption;
|
||||
#[derive(
|
||||
Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, FromForm,
|
||||
)]
|
||||
|
||||
pub struct SharedProcess {
|
||||
pub hash: String,
|
||||
pub key: KeyEncryption,
|
||||
pub role_process_sp_address_list: Vec<String>,
|
||||
}
|
||||
|
||||
impl SharedProcess {
|
||||
pub fn new(
|
||||
hash: String,
|
||||
key: KeyEncryption,
|
||||
role_process_sp_address_list: Vec<String>,
|
||||
) -> Self {
|
||||
SharedProcess {
|
||||
hash,
|
||||
key,
|
||||
role_process_sp_address_list,
|
||||
}
|
||||
}
|
||||
// display_info method
|
||||
pub fn display_info(&self) {
|
||||
println!("SharedProcess:");
|
||||
println!("Hash: {}", self.hash);
|
||||
println!("Key Encryption:");
|
||||
self.key.display_info(); // Assuming KeyEncryption has a display_info method
|
||||
println!(
|
||||
"Role Process SP Address List: {:?}",
|
||||
self.role_process_sp_address_list
|
||||
);
|
||||
}
|
||||
}
|
27
src/wallet.rs
Normal file
27
src/wallet.rs
Normal file
@ -0,0 +1,27 @@
|
||||
// use rand::{rngs::ThreadRng, thread_rng};
|
||||
// use silentpayments::secp256k1::{self, Secp256k1, SecretKey};
|
||||
|
||||
// use sp_backend::SpClient;
|
||||
/*
|
||||
pub struct Wallet {
|
||||
pub client: SpClient,
|
||||
pub secp: Secp256k1<secp256k1::All>,
|
||||
pub seckey_spend: SecretKey,
|
||||
pub seckey_scan: SecretKey,
|
||||
}
|
||||
|
||||
impl Wallet {
|
||||
pub fn new() -> Wallet {
|
||||
let secp: Secp256k1<secp256k1::All> = Secp256k1::new();
|
||||
let mut rng: ThreadRng = thread_rng();
|
||||
let seckey_spend: SecretKey = SecretKey::new(rng);
|
||||
let seckey_scan: SecretKey = SecretKey::new(rng);
|
||||
Wallet {
|
||||
client: SpClient::new(),
|
||||
secp,
|
||||
seckey_spend,
|
||||
seckey_scan,
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
0
src/workflows/lib.rs
Normal file
0
src/workflows/lib.rs
Normal file
1
src/workflows/mod.rs
Normal file
1
src/workflows/mod.rs
Normal file
@ -0,0 +1 @@
|
||||
pub mod workflow_pcd_create_and_send_all;
|
254
src/workflows/workflow_pcd_create_and_send_all.rs
Normal file
254
src/workflows/workflow_pcd_create_and_send_all.rs
Normal file
@ -0,0 +1,254 @@
|
||||
use crate::models::{
|
||||
commitment_method::CommitmentMethod, deposit_method::DepositMethod, item_enum::ItemEnum,
|
||||
message_client::MessageClient, payment_method::PaymentMethod, roles_group::RolesGroup,
|
||||
};
|
||||
|
||||
use rocket::FromForm;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::hash::Hash;
|
||||
|
||||
use crate::models::{
|
||||
key_encryption::KeyEncryption, pagination::Pagination, request_pcd::RequestPcd,
|
||||
shared_peer::SharedPeer, shared_process::SharedProcess,
|
||||
};
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, FromForm)]
|
||||
pub struct ProcessRoleSpAddressGroup {
|
||||
pub sp_address_list: Vec<String>,
|
||||
pub role_name: String,
|
||||
}
|
||||
impl ProcessRoleSpAddressGroup {
|
||||
pub fn new(sp_address_list: Vec<String>, role_name: String) -> Self {
|
||||
ProcessRoleSpAddressGroup {
|
||||
sp_address_list,
|
||||
role_name,
|
||||
}
|
||||
}
|
||||
pub fn display_info(&self) {
|
||||
println!("ProcessRoleSpAddressGroup:");
|
||||
println!("SP Address List: {:?}", self.sp_address_list);
|
||||
println!("Role Name: {}", self.role_name);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, FromForm)]
|
||||
|
||||
pub struct PcdItemEncAttributeRoleConfidentialExportKey {
|
||||
pub attribute_name: String,
|
||||
pub key: Option<KeyEncryption>,
|
||||
pub item_index: usize,
|
||||
}
|
||||
|
||||
pub struct WorkflowPcdCreateAndSendAll {
|
||||
pub item_name: String,
|
||||
pub item_list: Vec<ItemEnum>,
|
||||
pub pcd_pagination: Pagination,
|
||||
pub pcd_version: i64,
|
||||
pub process_hash: String,
|
||||
pub pcd_reference_hash: Option<String>,
|
||||
pub pcd_item_reference_hash: Option<String>,
|
||||
pub member_private_enc_key: KeyEncryption,
|
||||
pub process_public_enc_key: KeyEncryption,
|
||||
pub roles: RolesGroup,
|
||||
pub pow_pathern: String,
|
||||
pub pow_difficulty: usize,
|
||||
pub message_shared_peer_list: Vec<SharedPeer>,
|
||||
pub message_shared_process_list: Vec<SharedProcess>,
|
||||
pub message_faucet_sp_address: String,
|
||||
|
||||
pub message_public_string: Option<String>,
|
||||
pub message_confidential_string: Option<String>,
|
||||
pub message_private_string: Option<String>,
|
||||
pub sp_address_from: String,
|
||||
pub sp_address_reply: String,
|
||||
pub timestamp_declared: u64,
|
||||
pub role_name_from: String,
|
||||
pub role_name_to: String,
|
||||
pub sig_value: String,
|
||||
pub pcd_origin_hash: Option<String>,
|
||||
|
||||
pub payment_method: Option<PaymentMethod>,
|
||||
pub deposit_method: Option<DepositMethod>,
|
||||
pub commitment_method: Option<CommitmentMethod>,
|
||||
pub certif_key: Option<String>,
|
||||
}
|
||||
|
||||
impl WorkflowPcdCreateAndSendAll {
|
||||
pub fn new(
|
||||
item_name: String,
|
||||
item_list: Vec<ItemEnum>,
|
||||
pcd_pagination: Pagination,
|
||||
pcd_version: i64,
|
||||
process_hash: String,
|
||||
pcd_reference_hash: Option<String>,
|
||||
pcd_item_reference_hash: Option<String>,
|
||||
member_private_enc_key: KeyEncryption,
|
||||
process_public_enc_key: KeyEncryption,
|
||||
roles: RolesGroup,
|
||||
pow_pathern: String,
|
||||
pow_difficulty: usize,
|
||||
message_shared_peer_list: Vec<SharedPeer>,
|
||||
message_shared_process_list: Vec<SharedProcess>,
|
||||
message_faucet_sp_address: String,
|
||||
message_public_string: Option<String>,
|
||||
message_confidential_string: Option<String>,
|
||||
message_private_string: Option<String>,
|
||||
sp_address_from: String,
|
||||
sp_address_reply: String,
|
||||
timestamp_declared: u64,
|
||||
role_name_from: String,
|
||||
role_name_to: String,
|
||||
sig_value: String,
|
||||
pcd_origin_hash: Option<String>,
|
||||
|
||||
payment_method: Option<PaymentMethod>,
|
||||
deposit_method: Option<DepositMethod>,
|
||||
commitment_method: Option<CommitmentMethod>,
|
||||
certif_key: Option<String>,
|
||||
) -> Self {
|
||||
WorkflowPcdCreateAndSendAll {
|
||||
item_name,
|
||||
item_list,
|
||||
pcd_pagination,
|
||||
pcd_version,
|
||||
process_hash,
|
||||
pcd_reference_hash,
|
||||
pcd_item_reference_hash,
|
||||
member_private_enc_key,
|
||||
process_public_enc_key,
|
||||
roles,
|
||||
pow_pathern,
|
||||
pow_difficulty,
|
||||
message_shared_peer_list,
|
||||
message_shared_process_list,
|
||||
message_faucet_sp_address,
|
||||
|
||||
message_public_string,
|
||||
message_confidential_string,
|
||||
message_private_string,
|
||||
sp_address_from,
|
||||
sp_address_reply,
|
||||
timestamp_declared,
|
||||
role_name_from,
|
||||
role_name_to,
|
||||
sig_value,
|
||||
pcd_origin_hash,
|
||||
payment_method,
|
||||
deposit_method,
|
||||
commitment_method,
|
||||
certif_key,
|
||||
}
|
||||
}
|
||||
pub fn run(&self) {
|
||||
// walk item list and encrypt attributes
|
||||
|
||||
// create pcd
|
||||
let pcd: RequestPcd = RequestPcd::new(
|
||||
Some(self.item_name.clone()),
|
||||
self.pcd_version,
|
||||
self.process_hash.clone(),
|
||||
self.pcd_reference_hash.clone(),
|
||||
self.pcd_item_reference_hash.clone(),
|
||||
self.item_list.clone(),
|
||||
self.pcd_pagination.clone(),
|
||||
self.process_public_enc_key.clone(),
|
||||
self.member_private_enc_key.clone(),
|
||||
);
|
||||
|
||||
let pcd_message: MessageClient = pcd.to_message(
|
||||
self.process_public_enc_key.clone(),
|
||||
self.message_shared_peer_list.clone(),
|
||||
self.message_shared_process_list.clone(),
|
||||
self.message_faucet_sp_address.clone(),
|
||||
self.pow_pathern.clone(),
|
||||
self.pow_difficulty,
|
||||
);
|
||||
|
||||
let mut pcd_keys_role_confidential_list: Vec<PcdItemEncAttributeRoleConfidentialExportKey> =
|
||||
Vec::new();
|
||||
|
||||
let mut item_index = 0;
|
||||
for item in &pcd.item_list {
|
||||
for enc_attribute_list in &item.pcd_item_enc_attribute_role_confidential_list {
|
||||
for enc_attribute in enc_attribute_list {
|
||||
let exp = PcdItemEncAttributeRoleConfidentialExportKey {
|
||||
attribute_name: enc_attribute.attribute_name.clone(),
|
||||
key: Some(enc_attribute.key.clone()),
|
||||
item_index,
|
||||
};
|
||||
pcd_keys_role_confidential_list.push(exp);
|
||||
}
|
||||
}
|
||||
item_index += 1;
|
||||
}
|
||||
|
||||
let prd_list = self.roles.to_prd_response_list(
|
||||
self.process_public_enc_key.clone(),
|
||||
self.member_private_enc_key.clone(),
|
||||
Some(self.item_name.clone()),
|
||||
0,
|
||||
self.process_hash.clone(),
|
||||
self.pcd_reference_hash.clone(),
|
||||
self.pcd_item_reference_hash.clone(),
|
||||
pcd_keys_role_confidential_list.clone(),
|
||||
self.message_public_string.clone(),
|
||||
self.message_confidential_string.clone(),
|
||||
self.message_private_string.clone(),
|
||||
self.sp_address_from.clone(),
|
||||
self.sp_address_reply.clone(),
|
||||
self.timestamp_declared.clone(),
|
||||
self.role_name_from.clone(),
|
||||
self.role_name_to.clone(),
|
||||
self.sig_value.clone(),
|
||||
Some(pcd_message.request_hash),
|
||||
self.payment_method.clone(),
|
||||
self.deposit_method.clone(),
|
||||
self.commitment_method.clone(),
|
||||
self.certif_key.clone(),
|
||||
);
|
||||
|
||||
for prd in prd_list {
|
||||
let _prd_message_list = prd.to_message(
|
||||
self.process_public_enc_key.clone(),
|
||||
self.message_shared_peer_list.clone(),
|
||||
self.message_shared_process_list.clone(),
|
||||
self.message_faucet_sp_address.clone(),
|
||||
self.pow_pathern.clone(),
|
||||
self.pow_difficulty,
|
||||
);
|
||||
}
|
||||
// todo
|
||||
// send
|
||||
}
|
||||
pub fn display_info(&self) {
|
||||
println!("PcdCreateAndSend:");
|
||||
println!("Item Name: {}", self.item_name);
|
||||
println!("Item List: {:?}", self.item_list);
|
||||
println!("Pagination: {:?}", self.pcd_pagination);
|
||||
println!("Version: {}", self.pcd_version);
|
||||
println!("Process Hash: {}", self.process_hash);
|
||||
println!("Reference Hash: {:?}", self.pcd_reference_hash);
|
||||
println!("Item Reference Hash: {:?}", self.pcd_item_reference_hash);
|
||||
println!(
|
||||
"Member Private Encryption Key: {:?}",
|
||||
self.member_private_enc_key
|
||||
);
|
||||
println!(
|
||||
"Process Public Encryption Key: {:?}",
|
||||
self.process_public_enc_key
|
||||
);
|
||||
println!("Process roles: {:?}", self.roles);
|
||||
println!(
|
||||
"Message Shared Peer List: {:?}",
|
||||
self.message_shared_peer_list
|
||||
);
|
||||
println!(
|
||||
"Message Shared Process List: {:?}",
|
||||
self.message_shared_process_list
|
||||
);
|
||||
println!(
|
||||
"Message Faucet SP Address: {:?}",
|
||||
self.message_faucet_sp_address
|
||||
);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user