open Types

type t = {
  pub: EddsaPublicKey.t;
  stamp_start: Ptime.t;
  stamp_expire: Ptime.t;
  stamp_end: Ptime.t;
  sign: string -> EddsaSignature.t;
  (* signature of this key by offline master key *)
  master_sig: EddsaSignature.t option;
}

let generate () =
  (* TODO
       - look if it exists
       - if not, create it (TOFU initialization scheme)
       - write it *)
  (* TODO time
     correctly set those: *)
  let stamp_start = Ptime_clock.now () in
  let stamp_expire =
    Util.ptime_add_span_exn stamp_start Config.Exchange.signkey_legal_duration
  in
  let stamp_end = stamp_expire in
  let priv, pub = Mirage_crypto_ec.Ed25519.generate () in
  let sign s = EddsaSignature.sign ~key:priv s in
  let master_sig = None in
  { pub; stamp_start; stamp_expire; stamp_end; master_sig; sign }
