From 7836f5771b3a21c8eee5ab9c64faeaa002df918b Mon Sep 17 00:00:00 2001 From: aniampio Date: Tue, 24 Oct 2023 14:49:56 +0100 Subject: [PATCH] Add function generating the payinfo --- .DS_Store | Bin 8196 -> 8196 bytes Cargo.lock | 6 +++++ common/nym_offline_compact_ecash/Cargo.toml | 1 + .../src/scheme/mod.rs | 22 +++++++++++++++++- 4 files changed, 28 insertions(+), 1 deletion(-) diff --git a/.DS_Store b/.DS_Store index 982829a9ace8c734aa4e322bdb5540432e51b5a1..386404c70e054b7966559233dfd146af8010e888 100644 GIT binary patch delta 105 zcmZp1XmOa}&nUAoU^hRb%w!&c^OM;Hix_uKt`aQNkgTpYG_$nSQ7|^LtkqGdwlp%( zQ7|z!tF7ha5LMQ<4vNpt$<52}o-8UP&)BosR7jn9^Ayoyril${o7pA4u}sz$HG~Qz F0|0h%AOrva delta 171 zcmZp1XmOa}&nUMsU^hRb++-es^So>f$qYFRnGC56c?>0!1%-ttpBJcO+&$S(uux07 zx?0!J#KJ^J!N|m*R!5=Q(7?z{N5Ra{sJ51qLsVJcIw(FnCpRy@ck**VdB(oY>_Y0y wqC5=63~3DI47v;j3`Gq23}rymQzj=0iEUOCZD88WF7b_J@_CVXyy|M10CFoVvH$=8 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,