mte/src/management.ml

122 lines
3.5 KiB
OCaml
Raw Normal View History

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-16 10:18:22 +02:00
let ps =
let h_denom_pub =
(* TODO hash *)
2025-10-17 15:09:47 +02:00
let v = pub |> RsaPublicKey.to_string in
2025-10-16 10:18:22 +02:00
Binary_formats.DenominationHash.{ v= { v } }
in
let h_section_name =
(* TODO hash *)
let v = section_name in
Binary_formats.HashCode.{ v }
in
let anchor_time = Binary_formats.TimeAbsoluteNBO.{ v= 0_L } in
let duration_withdraw = Binary_formats.TimeRelativeNBO.{ v= 0_L } in
Binary_formats.DenominationKeyAnnouncementPS.
{ h_denom_pub; h_section_name; anchor_time; duration_withdraw }
in
let denom_secmod_sig =
ps
|>
(* TODO implement
DenominationKeyAnnouncementPS.bin
SigningKeyAnnouncementPS.bin *)
Binary_formats.DenominationKeyAnnouncementPS.to_string
|>
(* TODO sig type *)
(* Signature by the denomination security module
not this denomination rsa signature *)
denom_secmod_sign_f
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 15:09:47 +02:00
let v = EddsaPublicKey.to_string pub in
2025-10-16 10:18:22 +02:00
Binary_formats.ExchangePublicKeyP.{ v= { v } }
in
let signing_key_announcement_ps =
2025-10-17 15:09:47 +02:00
let anchor_time =
Binary_formats.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
Binary_formats.TimeRelativeNBO.{ v }
in
2025-10-16 10:18:22 +02:00
Binary_formats.SigningKeyAnnouncementPS.
{ exchange_pub; anchor_time; duration }
in
let signkey_secmod_sig = signkey_secmod_sign_f signing_key_announcement_ps 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