This commit is contained in:
parent
6962399dba
commit
585838c16d
7 changed files with 44 additions and 35 deletions
|
|
@ -81,8 +81,6 @@ module TimeAbsolute : Time_S = TIME
|
||||||
module TimeAbsoluteNBO : Time_S = TIME_NBO
|
module TimeAbsoluteNBO : Time_S = TIME_NBO
|
||||||
module TimeRelative : Time_S = TIME
|
module TimeRelative : Time_S = TIME
|
||||||
module TimeRelativeNBO : Time_S = TIME_NBO
|
module TimeRelativeNBO : Time_S = TIME_NBO
|
||||||
module Timestamp : Time_S = TIME
|
|
||||||
module TimestampNBO : Time_S = TIME_NBO
|
|
||||||
|
|
||||||
(* -- Cryptographic primitives -- *)
|
(* -- Cryptographic primitives -- *)
|
||||||
|
|
||||||
|
|
@ -230,6 +228,12 @@ end
|
||||||
(* TODO keep this?
|
(* TODO keep this?
|
||||||
some of those are actuall ecdhe, or union of eddsa|ecdhe *)
|
some of those are actuall ecdhe, or union of eddsa|ecdhe *)
|
||||||
module Aliases = struct
|
module Aliases = struct
|
||||||
|
module TimestampNBO : Time_S = struct
|
||||||
|
type t = Timestamp.t
|
||||||
|
|
||||||
|
let bin = Timestamp.bin_nbo
|
||||||
|
end
|
||||||
|
|
||||||
module AmountNBO = struct
|
module AmountNBO = struct
|
||||||
type t = Amount.t
|
type t = Amount.t
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -36,17 +36,16 @@ let make
|
||||||
Config.Coin.t) =
|
Config.Coin.t) =
|
||||||
assert (cipher = `RSA);
|
assert (cipher = `RSA);
|
||||||
|
|
||||||
let stamp_start = Ptime_clock.now () in
|
let stamp_start = Ptime_clock.now () |> Option.some in
|
||||||
let stamp_expire_withdraw =
|
let stamp_expire_withdraw =
|
||||||
Util.ptime_add_span_exn stamp_start duration_withdraw |> Option.some
|
Timestamp.add_span_exn stamp_start (Some duration_withdraw)
|
||||||
in
|
in
|
||||||
let stamp_expire_deposit =
|
let stamp_expire_deposit =
|
||||||
Util.ptime_add_span_exn stamp_start duration_spend |> Option.some
|
Timestamp.add_span_exn stamp_start (Some duration_spend)
|
||||||
in
|
in
|
||||||
let stamp_expire_legal =
|
let stamp_expire_legal =
|
||||||
Util.ptime_add_span_exn stamp_start duration_legal |> Option.some
|
Timestamp.add_span_exn stamp_start (Some duration_legal)
|
||||||
in
|
in
|
||||||
let stamp_start = Some stamp_start in
|
|
||||||
|
|
||||||
let open Mirage_crypto_pk.Rsa in
|
let open Mirage_crypto_pk.Rsa in
|
||||||
let priv = generate ~bits:rsa_keysize () in
|
let priv = generate ~bits:rsa_keysize () in
|
||||||
|
|
|
||||||
|
|
@ -30,9 +30,7 @@ let mk_future_denom denom_key_signf
|
||||||
let h_section_name = Hash_64_cstr.hash section_name in
|
let h_section_name = Hash_64_cstr.hash section_name in
|
||||||
let anchor_time = stamp_start in
|
let anchor_time = stamp_start in
|
||||||
let duration_withdraw =
|
let duration_withdraw =
|
||||||
None
|
Timestamp.diff stamp_start stamp_expire_withdraw |> Timestamp.of_span_exn
|
||||||
(* TODO time
|
|
||||||
Ptime.diff stamp_start stamp_expire_withdraw |> Util.ptime_of_span_exn*)
|
|
||||||
in
|
in
|
||||||
let ps = { h_denom_pub; h_section_name; anchor_time; duration_withdraw } in
|
let ps = { h_denom_pub; h_section_name; anchor_time; duration_withdraw } in
|
||||||
ps |> Bin.to_string bin |> denom_key_signf
|
ps |> Bin.to_string bin |> denom_key_signf
|
||||||
|
|
@ -61,11 +59,7 @@ let mk_future_signkey signkey_signf
|
||||||
let exchange_pub = pub in
|
let exchange_pub = pub in
|
||||||
let anchor_time = stamp_start in
|
let anchor_time = stamp_start in
|
||||||
let duration =
|
let duration =
|
||||||
None
|
Timestamp.diff stamp_start stamp_expire |> Timestamp.of_span_exn
|
||||||
(* TODO time
|
|
||||||
Ptime.diff stamp_start stamp_expire
|
|
||||||
|> Util.ptime_of_span_exn
|
|
||||||
*)
|
|
||||||
in
|
in
|
||||||
let ps = { exchange_pub; anchor_time; duration } in
|
let ps = { exchange_pub; anchor_time; duration } in
|
||||||
ps |> Bin.to_string bin |> signkey_signf
|
ps |> Bin.to_string bin |> signkey_signf
|
||||||
|
|
|
||||||
|
|
@ -17,15 +17,12 @@ let generate () =
|
||||||
- look if it exists
|
- look if it exists
|
||||||
- if not, create it (TOFU initialization scheme)
|
- if not, create it (TOFU initialization scheme)
|
||||||
- write it *)
|
- write it *)
|
||||||
(* TODO time
|
let stamp_start = Ptime_clock.now () |> Option.some in
|
||||||
correctly set those: *)
|
|
||||||
let stamp_start = Ptime_clock.now () in
|
|
||||||
let stamp_expire =
|
let stamp_expire =
|
||||||
Util.ptime_add_span_exn stamp_start Config.Exchange.signkey_legal_duration
|
Timestamp.add_span_exn stamp_start
|
||||||
|> Option.some
|
(Some Config.Exchange.signkey_legal_duration)
|
||||||
in
|
in
|
||||||
let stamp_end = stamp_expire in
|
let stamp_end = stamp_expire in
|
||||||
let stamp_start = Some stamp_start in
|
|
||||||
|
|
||||||
let priv, pub = Mirage_crypto_ec.Ed25519.generate () in
|
let priv, pub = Mirage_crypto_ec.Ed25519.generate () in
|
||||||
let master_sig = None in
|
let master_sig = None in
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,27 @@
|
||||||
type t = Ptime.t option
|
type t = Ptime.t option
|
||||||
|
type span = Ptime.Span.t option
|
||||||
|
|
||||||
|
let diff a b =
|
||||||
|
match (a, b) with
|
||||||
|
| None, _ | _, None -> None
|
||||||
|
| Some a, Some b -> Some (Ptime.diff a b)
|
||||||
|
|
||||||
|
let add_span_exn t span =
|
||||||
|
match (t, span) with
|
||||||
|
| None, _ | _, None -> None
|
||||||
|
| Some t, Some span -> (
|
||||||
|
match Ptime.add_span t span with
|
||||||
|
| None -> Fmt.failwith "add_span_exn: not in the range [min;max]"
|
||||||
|
| Some v -> Some v)
|
||||||
|
|
||||||
|
let of_span_exn = function
|
||||||
|
| None -> None
|
||||||
|
| Some span -> (
|
||||||
|
match Ptime.of_span span with
|
||||||
|
| None -> Fmt.failwith "of_span_exn: not in the range [min;max]"
|
||||||
|
| Some p -> Some p)
|
||||||
|
|
||||||
|
(* -- *)
|
||||||
|
|
||||||
(* microseconds since the UNIX Epoch, or "never" if None *)
|
(* microseconds since the UNIX Epoch, or "never" if None *)
|
||||||
let jsont =
|
let jsont =
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,13 @@
|
||||||
not sure about this *)
|
not sure about this *)
|
||||||
|
|
||||||
type t = Ptime.t option
|
type t = Ptime.t option
|
||||||
|
type span = Ptime.Span.t option
|
||||||
|
|
||||||
|
val diff : t -> t -> span
|
||||||
|
val add_span_exn : t -> span -> t
|
||||||
|
val of_span_exn : span -> t
|
||||||
|
|
||||||
|
(* - *)
|
||||||
val jsont : t Jsont.t
|
val jsont : t Jsont.t
|
||||||
val bin : t Bin.t
|
val bin : t Bin.t
|
||||||
val bin_nbo : t Bin.t
|
val bin_nbo : t Bin.t
|
||||||
|
|
|
||||||
14
src/util.ml
14
src/util.ml
|
|
@ -1,17 +1,3 @@
|
||||||
(* -- Ptime -- *)
|
|
||||||
|
|
||||||
let ptime_of_span_exn span =
|
|
||||||
match Ptime.of_span span with
|
|
||||||
| None -> Fmt.failwith "Ptime.of_span: not in the range [min;max]"
|
|
||||||
| Some p -> p
|
|
||||||
|
|
||||||
let ptime_add_span_exn p span =
|
|
||||||
match Ptime.add_span p span with
|
|
||||||
| None -> Fmt.failwith "Ptime.add_span: not in the range [min;max]"
|
|
||||||
| Some v -> v
|
|
||||||
|
|
||||||
(* -- *** -- *)
|
|
||||||
|
|
||||||
(* TODO bin
|
(* TODO bin
|
||||||
- no [Bin.of_string] ? *)
|
- no [Bin.of_string] ? *)
|
||||||
let bin_of_string bin s =
|
let bin_of_string bin s =
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue