2025-09-21 17:44:14 +02:00
|
|
|
(* MTE - the MirageOS Taler Exchange
|
|
|
|
|
Copyright (C) 2025 Olivier Pierre <swrup@protonmail.com>
|
|
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Affero General Public License as published by
|
2025-09-28 16:58:47 +02:00
|
|
|
the Free Software Foundation, version 3.
|
2025-09-21 17:44:14 +02:00
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
|
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>. *)
|
|
|
|
|
|
2025-09-28 20:04:52 +02:00
|
|
|
let hello req _server _env =
|
2026-03-12 12:23:57 +01:00
|
|
|
let open Vifu.Response in
|
2025-09-28 22:12:16 +02:00
|
|
|
let open Syntax in
|
|
|
|
|
let* () = with_string req "Hello~~\n" in
|
|
|
|
|
let* () = add ~field:"content-type" "text/plain" in
|
|
|
|
|
respond `OK
|
2025-09-28 20:04:52 +02:00
|
|
|
|
2026-03-14 18:47:57 +01:00
|
|
|
(* TODO nice routes typing
|
|
|
|
|
to enforce json verification
|
2026-03-14 19:37:16 +01:00
|
|
|
to specify handlers responses data and status codes
|
|
|
|
|
|
|
|
|
|
use Vif.Uri.conv *)
|
2025-09-13 15:56:19 +02:00
|
|
|
let routes =
|
2026-03-12 12:23:57 +01:00
|
|
|
let open Vifu.Uri in
|
|
|
|
|
let open Vifu.Route in
|
2026-02-12 12:13:30 +01:00
|
|
|
let get path = get (path /?? any) in
|
2026-03-12 12:23:57 +01:00
|
|
|
let post path jsont = post (Vifu.Type.json_encoding jsont) (path /?? any) in
|
2026-02-12 12:13:30 +01:00
|
|
|
let v s = rel / s in
|
2026-01-19 20:54:39 +01:00
|
|
|
let tos =
|
2025-12-11 09:54:40 +01:00
|
|
|
[
|
2026-02-12 12:13:30 +01:00
|
|
|
get rel --> hello;
|
2026-03-03 10:09:03 +01:00
|
|
|
get (v "terms") --> Mte_terms.terms;
|
|
|
|
|
get (v "privacy") --> Mte_terms.privacy;
|
2025-12-11 09:54:40 +01:00
|
|
|
]
|
|
|
|
|
in
|
2026-02-07 21:03:21 +01:00
|
|
|
let status_info =
|
2026-02-07 21:22:29 +01:00
|
|
|
[
|
2026-03-03 10:09:03 +01:00
|
|
|
get (v "seed") --> Mte_info.seed;
|
|
|
|
|
get (v "config") --> Mte_info.config;
|
|
|
|
|
get (v "keys") --> Mte_info.keys;
|
2026-02-07 21:22:29 +01:00
|
|
|
]
|
2026-02-07 21:03:21 +01:00
|
|
|
in
|
2025-12-11 09:54:40 +01:00
|
|
|
let management =
|
2026-03-03 10:09:03 +01:00
|
|
|
let open Mte_management in
|
2026-02-12 12:13:30 +01:00
|
|
|
let v s = v "management" / s in
|
2025-12-11 09:54:40 +01:00
|
|
|
[
|
2026-02-12 12:13:30 +01:00
|
|
|
get (v "keys") --> Keys_get.f;
|
2025-12-11 09:54:40 +01:00
|
|
|
post (v "keys") Keys_post.jsont --> Keys_post.f;
|
|
|
|
|
post (v "denominations" /% string `Path / "revoke") Denom_revoke.jsont
|
|
|
|
|
--> Denom_revoke.f;
|
|
|
|
|
post (v "signkeys" /% string `Path / "revoke") Signkey_revoke.jsont
|
|
|
|
|
--> Signkey_revoke.f;
|
|
|
|
|
post (v "auditors") Auditors.jsont --> Auditors.f;
|
|
|
|
|
post (v "auditors" /% string `Path / "disable") Auditors_disable.jsont
|
|
|
|
|
--> Auditors_disable.f;
|
|
|
|
|
post (v "wire-fee") Wire_fee.jsont --> Wire_fee.f;
|
|
|
|
|
post (v "global-fees") Global_fees.jsont --> Global_fees.f;
|
|
|
|
|
post (v "wire") Wire.jsont --> Wire.f;
|
|
|
|
|
post (v "wire" / "disable") Wire_disable.jsont --> Wire_disable.f;
|
|
|
|
|
post (v "drain") Drain.jsont --> Drain.f;
|
|
|
|
|
post (v "aml-officers") AmlOfficer.jsont --> AmlOfficer.f;
|
|
|
|
|
post (v "partners") Partners.jsont --> Partners.f;
|
|
|
|
|
]
|
|
|
|
|
in
|
2026-01-19 20:54:39 +01:00
|
|
|
tos @ status_info @ management
|
2025-09-13 15:56:19 +02:00
|
|
|
|
2026-03-12 12:08:21 +01:00
|
|
|
module RNG = Mirage_crypto_rng.Fortuna
|
|
|
|
|
|
2025-09-13 17:57:29 +02:00
|
|
|
let () =
|
2026-03-12 12:08:21 +01:00
|
|
|
let ( let@ ) finally fn = Fun.protect ~finally fn in
|
2025-11-29 19:36:35 +01:00
|
|
|
Util.Log_reporter.setup ();
|
2026-03-12 12:11:47 +01:00
|
|
|
let rng =
|
|
|
|
|
let rng () = Mirage_crypto_rng_mkernel.initialize (module RNG) in
|
|
|
|
|
Mkernel.map rng Mkernel.[]
|
|
|
|
|
in
|
2026-03-12 18:56:19 +01:00
|
|
|
let storage = Mkernel.block "storage" in
|
2026-03-12 12:08:21 +01:00
|
|
|
let service =
|
|
|
|
|
let ipv4 = Ipaddr.V4.Prefix.of_string_exn "10.0.0.2/24" in
|
2026-03-14 18:47:57 +01:00
|
|
|
Mnet.stack ~name:"service" ipv4
|
2026-03-12 12:08:21 +01:00
|
|
|
in
|
2026-03-12 18:56:19 +01:00
|
|
|
Mkernel.(run [ rng; storage; service ])
|
|
|
|
|
@@ fun rng storage (stack, tcp, udp) () ->
|
2026-03-12 12:08:21 +01:00
|
|
|
let@ () = fun () -> Mirage_crypto_rng_mkernel.kill rng in
|
|
|
|
|
let@ () = fun () -> Mnet.kill stack in
|
|
|
|
|
let hed, he = Mnet_happy_eyeballs.create tcp in
|
|
|
|
|
let@ () = fun () -> Mnet_happy_eyeballs.kill hed in
|
2026-03-12 13:23:27 +01:00
|
|
|
let dns = Mnet_dns.create (udp, he) in
|
2026-03-12 12:08:21 +01:00
|
|
|
let t = Mnet_dns.transport dns in
|
|
|
|
|
let@ () = fun () -> Mnet_dns.Transport.kill t in
|
|
|
|
|
Caqti_miou.Switch.run @@ fun sw ->
|
|
|
|
|
(* -- *)
|
2026-03-12 18:56:19 +01:00
|
|
|
let fs = Fat.create storage in
|
2026-03-12 17:49:51 +01:00
|
|
|
let env = Env.{ sw; stack; tcp; dns; fs } in
|
|
|
|
|
let devices = Vifu.Devices.[ Global.db_conn; Global.keys ] in
|
2026-03-12 12:08:21 +01:00
|
|
|
let cfg = Vifu.Config.v Config.Exchange.port in
|
2025-11-29 19:36:35 +01:00
|
|
|
Logs.info (fun m ->
|
|
|
|
|
m ~tags:(Util.Log_reporter.detail "...") "Starting MTE server");
|
2026-03-12 18:56:19 +01:00
|
|
|
Vifu.run ~cfg ~devices tcp routes env
|