Add function generating the payinfo

This commit is contained in:
aniampio
2023-10-24 14:49:56 +01:00
committed by durch
parent 46c53eb1a5
commit 7836f5771b
4 changed files with 28 additions and 1 deletions
Vendored
BIN
View File
Binary file not shown.
Generated
+6
View File
@@ -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",
@@ -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"
@@ -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<u8>{
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(&timestamp_bytes);
payinfo.extend_from_slice(&ppk_bytes);
payinfo
}
#[derive(Debug, Clone, PartialEq)]
pub struct Payment {
pub kappa: G2Projective,