2025-10-16 10:18:22 +02:00
|
|
|
open Types
|
|
|
|
|
|
|
|
|
|
(* TODO
|
|
|
|
|
- take secmod devices as param
|
2025-10-17 15:09:47 +02:00
|
|
|
- time stuff
|
2025-10-16 10:18:22 +02:00
|
|
|
- hash stuff
|
|
|
|
|
what is the hash algorithm
|
|
|
|
|
is it hash'ed then base32'ed in xxxP?
|
|
|
|
|
... *)
|
|
|
|
|
|
|
|
|
|
let mk_denomination_key rsa_pub =
|
|
|
|
|
DenominationKey.Rsa RsaDenominationKey.{ age_mask= 0; rsa_pub }
|
|
|
|
|
|
2025-10-17 15:09:47 +02:00
|
|
|
let mk_future_denom denom_secmod_sign_f
|
|
|
|
|
({
|
|
|
|
|
section_name;
|
|
|
|
|
value;
|
|
|
|
|
stamp_start;
|
|
|
|
|
stamp_expire_withdraw;
|
|
|
|
|
stamp_expire_deposit;
|
|
|
|
|
stamp_expire_legal;
|
|
|
|
|
fee_withdraw;
|
|
|
|
|
fee_deposit;
|
|
|
|
|
fee_refresh;
|
|
|
|
|
fee_refund;
|
|
|
|
|
pub;
|
|
|
|
|
sign= _;
|
|
|
|
|
} :
|
|
|
|
|
Secmod_denom.rsa_denom) =
|
|
|
|
|
let denom_pub = mk_denomination_key pub in
|
2025-10-17 16:24:59 +02:00
|
|
|
let denom_secmod_sig =
|
|
|
|
|
let open Binary_formats in
|
2025-10-16 10:18:22 +02:00
|
|
|
let h_denom_pub =
|
|
|
|
|
(* TODO hash *)
|
2025-10-17 16:50:21 +02:00
|
|
|
let v = pub |> Types.RsaPublicKey.to_b32 in
|
2025-10-17 16:24:59 +02:00
|
|
|
DenominationHash.{ v= { v } }
|
2025-10-16 10:18:22 +02:00
|
|
|
in
|
|
|
|
|
let h_section_name =
|
|
|
|
|
(* TODO hash *)
|
|
|
|
|
let v = section_name in
|
2025-10-17 16:24:59 +02:00
|
|
|
HashCode.{ v }
|
2025-10-16 10:18:22 +02:00
|
|
|
in
|
2025-10-17 16:24:59 +02:00
|
|
|
let anchor_time =
|
|
|
|
|
TimeAbsoluteNBO.{ v= Util.ptime_to_int64_us stamp_start }
|
|
|
|
|
in
|
|
|
|
|
let duration_withdraw =
|
|
|
|
|
let v =
|
|
|
|
|
Ptime.diff stamp_start stamp_expire_withdraw
|
|
|
|
|
|> Util.ptime_of_span_exn
|
|
|
|
|
|> Util.ptime_to_int64_us
|
|
|
|
|
in
|
|
|
|
|
TimeRelativeNBO.{ v }
|
|
|
|
|
in
|
|
|
|
|
let ps =
|
|
|
|
|
DenominationKeyAnnouncementPS.
|
|
|
|
|
{ h_denom_pub; h_section_name; anchor_time; duration_withdraw }
|
|
|
|
|
in
|
|
|
|
|
ps |> Bin.to_string DenominationKeyAnnouncementPS.bin |> denom_secmod_sign_f
|
2025-10-16 10:18:22 +02:00
|
|
|
in
|
|
|
|
|
FutureDenom.
|
|
|
|
|
{
|
|
|
|
|
section_name;
|
|
|
|
|
value;
|
2025-10-17 15:09:47 +02:00
|
|
|
stamp_start= Timestamp.of_ptime stamp_start;
|
|
|
|
|
stamp_expire_withdraw= Timestamp.of_ptime stamp_expire_withdraw;
|
|
|
|
|
stamp_expire_deposit= Timestamp.of_ptime stamp_expire_deposit;
|
|
|
|
|
stamp_expire_legal= Timestamp.of_ptime stamp_expire_legal;
|
2025-10-16 10:18:22 +02:00
|
|
|
denom_pub;
|
|
|
|
|
fee_withdraw;
|
|
|
|
|
fee_deposit;
|
|
|
|
|
fee_refresh;
|
|
|
|
|
fee_refund;
|
|
|
|
|
denom_secmod_sig;
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-17 15:09:47 +02:00
|
|
|
let mk_future_sign_key signkey_secmod_sign_f
|
|
|
|
|
({ pub; sign= _; stamp_start; stamp_expire; stamp_end } : Secmod_keys.t) =
|
2025-10-16 10:18:22 +02:00
|
|
|
let exchange_pub =
|
|
|
|
|
(* TODO
|
|
|
|
|
- I don't think its in crockford base 32 here
|
|
|
|
|
maybe SHA-512?
|
|
|
|
|
or maybe SHA-512 in crockford base 32
|
|
|
|
|
-> no, its not a hash here
|
|
|
|
|
need to change ugly binary_formats functor
|
|
|
|
|
to not mixup hashed values with others
|
|
|
|
|
- have a make function for wrapped HashCode structs
|
|
|
|
|
make it take the relevant type *)
|
2025-10-17 16:50:21 +02:00
|
|
|
let v = EddsaPublicKey.to_b32 pub in
|
2025-10-16 10:18:22 +02:00
|
|
|
Binary_formats.ExchangePublicKeyP.{ v= { v } }
|
|
|
|
|
in
|
2025-10-17 16:24:59 +02:00
|
|
|
let signkey_secmod_sig =
|
|
|
|
|
let open Binary_formats in
|
|
|
|
|
let ps =
|
|
|
|
|
let anchor_time =
|
|
|
|
|
TimeAbsoluteNBO.{ v= Util.ptime_to_int64_us stamp_start }
|
|
|
|
|
in
|
|
|
|
|
let duration =
|
|
|
|
|
let v =
|
|
|
|
|
Ptime.diff stamp_start stamp_expire
|
|
|
|
|
|> Util.ptime_of_span_exn
|
|
|
|
|
|> Util.ptime_to_int64_us
|
|
|
|
|
in
|
|
|
|
|
TimeRelativeNBO.{ v }
|
2025-10-17 15:09:47 +02:00
|
|
|
in
|
2025-10-17 16:24:59 +02:00
|
|
|
SigningKeyAnnouncementPS.{ exchange_pub; anchor_time; duration }
|
2025-10-17 15:09:47 +02:00
|
|
|
in
|
2025-10-17 16:24:59 +02:00
|
|
|
ps |> Bin.to_string SigningKeyAnnouncementPS.bin |> signkey_secmod_sign_f
|
2025-10-16 10:18:22 +02:00
|
|
|
in
|
|
|
|
|
FutureSignKey.
|
|
|
|
|
{
|
2025-10-17 15:09:47 +02:00
|
|
|
key= pub;
|
|
|
|
|
stamp_start= Timestamp.of_ptime stamp_start;
|
|
|
|
|
stamp_expire= Timestamp.of_ptime stamp_expire;
|
|
|
|
|
stamp_end= Timestamp.of_ptime stamp_end;
|
2025-10-16 10:18:22 +02:00
|
|
|
signkey_secmod_sig;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let keys req _server _env =
|
|
|
|
|
let open Vif.Response in
|
|
|
|
|
let open Syntax in
|
|
|
|
|
let* () = with_string req "keys .. \n" in
|
|
|
|
|
let* () = add ~field:"content-type" "application/json" in
|
|
|
|
|
respond `OK
|