diff --git a/.DS_Store b/.DS_Store index 982829a9ac..386404c70e 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/Cargo.lock b/Cargo.lock index d0e8538ad4..bb4cdb0cd9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6442,8 +6442,14 @@ name = "nym-compact-ecash" version = "0.1.0" dependencies = [ "bls12_381 0.6.0", +<<<<<<< HEAD "bs58 0.4.0", "criterion 0.3.6", +======= + "bs58", + "chrono", + "criterion", +>>>>>>> 4a54fd93f (Add function generating the payinfo) "digest 0.9.0", "ff 0.11.1", "getset", diff --git a/common/nym_offline_compact_ecash/Cargo.toml b/common/nym_offline_compact_ecash/Cargo.toml index 77cf791466..09d35618ed 100644 --- a/common/nym_offline_compact_ecash/Cargo.toml +++ b/common/nym_offline_compact_ecash/Cargo.toml @@ -7,6 +7,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +chrono = "0.4.19" #bls12_381 = { version = "0.5", default-features = false, features = ["pairings", "alloc", "experimental"] } bls12_381 = { path = "/Users/simon/Documents/Nym/github/andrew_bls12_381", default-features = false, features = ["alloc", "pairings", "experimental", "zeroize"] } itertools = "0.10" diff --git a/common/nym_offline_compact_ecash/src/scheme/mod.rs b/common/nym_offline_compact_ecash/src/scheme/mod.rs index 473f2220c0..537f891bb1 100644 --- a/common/nym_offline_compact_ecash/src/scheme/mod.rs +++ b/common/nym_offline_compact_ecash/src/scheme/mod.rs @@ -7,7 +7,7 @@ use getset::{CopyGetters, Getters}; use crate::error::{CompactEcashError, Result}; use crate::proofs::proof_spend::{SpendInstance, SpendProof, SpendWitness}; -use crate::scheme::keygen::{SecretKeyUser, VerificationKeyAuth}; +use crate::scheme::keygen::{SecretKeyUser, VerificationKeyAuth, PublicKeyUser}; use crate::scheme::setup::{GroupParameters, Parameters}; use crate::traits::Bytable; use crate::utils::{ @@ -15,6 +15,8 @@ use crate::utils::{ try_deserialize_g2_projective, try_deserialize_scalar, Signature, SignerIndex, }; use crate::{Attribute, Base58}; +use chrono::{Utc, Timelike}; +use rand::{Rng, thread_rng}; pub mod aggregation; pub mod identify; @@ -316,6 +318,24 @@ pub struct PayInfo { pub info: [u8; 32], } +pub fn generate_payinfo(provider_pk: PublicKeyUser) -> Vec{ + let mut rng = thread_rng(); + let mut rbytes = [0u8; 32]; + rng.fill(&mut rbytes); + + let timestamp = Utc::now().timestamp(); + let timestamp_bytes: [u8; 8] = timestamp.to_be_bytes(); + + let ppk_bytes = provider_pk.pk.to_affine().to_compressed(); + + let mut payinfo = Vec::with_capacity(32 + 8 +48); + payinfo.extend_from_slice(&rbytes); + payinfo.extend_from_slice(×tamp_bytes); + payinfo.extend_from_slice(&ppk_bytes); + + payinfo +} + #[derive(Debug, Clone, PartialEq)] pub struct Payment { pub kappa: G2Projective,