Add redeem invite option. TODO: Get bucket

This commit is contained in:
Vecna 2023-09-07 15:25:58 -04:00
parent 849ca52f89
commit 4140419cb0
1 changed files with 28 additions and 9 deletions

View File

@ -34,6 +34,12 @@ fn save_object<T: Serialize>(obj: T, filename: &str) {
async fn main() {
let args: Vec<String> = args().collect();
// files used to store various data
let bucket_filename = "bucket.json";
let invite_filename = "invite.json";
let lox_auth_pubkeys_filename = "lox_auth_pubkeys.json";
let lox_cred_filename = "lox_cred.json";
let mut opts = Options::new();
opts.optflag("h", "help", "print this help menu");
//#[cfg(test)]
@ -46,6 +52,7 @@ async fn main() {
opts.optflag("I", "invite", "generate invitation for a friend");
opts.optflag("L", "level-up", "increase trust level");
opts.optflag("N", "new-lox-cred", "get a new Lox Credential");
opts.optflag("R", "redeem", "redeem invitation");
opts.optopt(
"",
"server",
@ -84,9 +91,6 @@ async fn main() {
}
// Get Lox Authority public keys
// TODO: Make this filename configurable
let lox_auth_pubkeys_filename = "lox_auth_pubkeys.json";
let lox_auth_pubkeys: Vec<IssuerPubKey> = if Path::new(lox_auth_pubkeys_filename).exists() {
// read in file
let lox_auth_pubkeys_infile = File::open(lox_auth_pubkeys_filename).unwrap();
@ -99,10 +103,26 @@ async fn main() {
pubkeys
};
// Get Lox Credential and BridgeLine
let lox_cred_filename = "lox_cred.json";
let bucket_filename = "bucket.json";
let (lox_cred, bucket) = if matches.opt_present("N")
// Get Lox Credential and Bucket
let (lox_cred, bucket) = if matches.opt_present("R") && Path::new(invite_filename).exists() {
// redeem invite
let invite_infile = File::open(invite_filename).unwrap();
let invite = serde_json::from_reader(invite_infile).unwrap();
let cred = redeem_invite(
&net,
&invite,
get_lox_pub(&lox_auth_pubkeys),
get_invitation_pub(&lox_auth_pubkeys),
)
.await;
let bucket = [BridgeLine::default(); MAX_BRIDGES_PER_BUCKET];
//TODO: let bucket = get_bucket();
// save to files for future use
save_object(&cred, &lox_cred_filename);
save_object(&bucket, &bucket_filename);
(cred, bucket)
} else if matches.opt_present("N")
|| !Path::new(lox_cred_filename).exists()
|| !Path::new(bucket_filename).exists()
{
@ -115,7 +135,7 @@ async fn main() {
// default (zeroed out) bridgelines
bucket[0] = bl;
// save to files for next time
// save to files for future use
save_object(&cred, &lox_cred_filename);
save_object(&bucket, &bucket_filename);
(cred, bucket)
@ -187,7 +207,6 @@ async fn main() {
)
.await;
// TODO: Make this unique per-run (e.g., add timestamp)
let invite_filename = "invite.json";
save_object(&invite, &invite_filename);
save_object(&cred, &lox_cred_filename);
println!("Invite saved in {}", &invite_filename);