diff --git a/dune-project b/dune-project index e2ec0c5..371ebe1 100644 --- a/dune-project +++ b/dune-project @@ -15,7 +15,15 @@ (synopsis "An atproto Personal Data Server implementation") (description "Eventually") (allow_empty) - (depends ocaml dune)) + (depends + ocaml + dune + lwt + (re (>= 1.13.2)) + (yojson (>= 3.0.0)) + (lwt_ppx (>= 5.9.1)) + (ppx_deriving_yojson (>= 3.9.1)) + (alcotest :with-test))) (package (name mist) @@ -24,13 +32,8 @@ (depends ocaml dune - (core_unix (>= 0.17.1)) - (cborl (>= 0.1.0)) - (cid (>= 0.1.0)) - (hacl-star (>= 0.7.2)) lwt - (mtime (>= 2.1.0)) - (multihash (>= 0.1.0)) + (core_unix (>= 0.17.1)) (re (>= 1.13.2)) (yojson (>= 3.0.0)) (lwt_ppx (>= 5.9.1)) @@ -45,10 +48,8 @@ (depends ocaml dune - (base64 (>= 3.5.1)) - (digestif (>= 1.2.0)) lwt - (multibase (>= 0.1.0)) + (digestif (>= 1.2.0)) (yojson (>= 3.0.0)) (lwt_ppx (>= 5.9.1)) (alcotest :with-test))) diff --git a/ipld.opam b/ipld.opam index 5ffa739..6f48bd0 100644 --- a/ipld.opam +++ b/ipld.opam @@ -10,10 +10,8 @@ bug-reports: "https://github.com/futurGH/pegasus/issues" depends: [ "ocaml" "dune" {>= "3.14"} - "base64" {>= "3.5.1"} "digestif" {>= "1.2.0"} "lwt" - "multibase" {>= "0.1.0"} "yojson" {>= "3.0.0"} "lwt_ppx" {>= "5.9.1"} "alcotest" {with-test} diff --git a/ipld/lib/dune b/ipld/lib/dune index 4c247fc..9b33585 100644 --- a/ipld/lib/dune +++ b/ipld/lib/dune @@ -1,6 +1,6 @@ (library (name ipld) (wrapped false) - (libraries base64 digestif lwt multibase yojson lwt_ppx) + (libraries digestif lwt multibase yojson lwt_ppx) (preprocess (pps lwt_ppx ppx_deriving_yojson))) diff --git a/mist.opam b/mist.opam index b8e11eb..e974fe4 100644 --- a/mist.opam +++ b/mist.opam @@ -10,12 +10,7 @@ depends: [ "ocaml" "dune" {>= "3.14"} "core_unix" {>= "0.17.1"} - "cborl" {>= "0.1.0"} - "cid" {>= "0.1.0"} - "hacl-star" {>= "0.7.2"} "lwt" - "mtime" {>= "2.1.0"} - "multihash" {>= "0.1.0"} "re" {>= "1.13.2"} "yojson" {>= "3.0.0"} "lwt_ppx" {>= "5.9.1"} diff --git a/mist/lib/dune b/mist/lib/dune index 1ae9339..872fd08 100644 --- a/mist/lib/dune +++ b/mist/lib/dune @@ -4,12 +4,9 @@ core_unix.time_stamp_counter core_unix.time_ns_unix digestif - hacl-star ipld lwt lwt.unix - mtime.clock - multihash re str yojson diff --git a/mist/test/test_mst.ml b/mist/test/test_mst.ml index de1df7a..147f205 100644 --- a/mist/test/test_mst.ml +++ b/mist/test/test_mst.ml @@ -1,7 +1,6 @@ open Mist open Lwt.Infix module MemMst = Mst.Make (Storage.Memory_blockstore) -module MemRepo = Repository.Make (Storage.Memory_blockstore) module StringMap = Dag_cbor.StringMap let cid_of_string_exn s = @@ -826,10 +825,24 @@ let test_roundtrip () = in let store = Storage.Memory_blockstore.create ~blocks:bm () in let%lwt commit = - MemRepo.read_commit store root - >|= function Ok commit -> commit | Error msg -> failwith msg + match%lwt Storage.Memory_blockstore.get_bytes store root with + | Some b -> ( + match Dag_cbor.decode b with + | `Map commit -> + Lwt.return commit + | _ -> + failwith "non-object commit" ) + | None -> + failwith "root not found in blockstore" + in + let mst = + MemMst.create store + ( match StringMap.find "data" commit with + | `Link cid -> + cid + | _ -> + failwith "non-cid data in commit" ) in - let mst = MemMst.create store commit.data in Lwt.return (commit, mst) in let%lwt ic = Lwt_io.open_file ~mode:Lwt_io.input "sample.car" in @@ -837,9 +850,7 @@ let test_roundtrip () = let%lwt () = Lwt_io.close ic in let%lwt commit, mst = mst_of_car_bytes car in let mst_stream = MemMst.to_blocks_stream mst in - let commit_bytes = - Dag_cbor.encode_yojson (Repository.signed_commit_to_yojson commit) - in + let commit_bytes = Dag_cbor.encode (`Map commit) in let commit_cid = Cid.create Dcbor commit_bytes in let%lwt car' = Car.blocks_to_car (Some commit_cid) diff --git a/pegasus.opam b/pegasus.opam index d1e0e9b..7b520d3 100644 --- a/pegasus.opam +++ b/pegasus.opam @@ -10,6 +10,12 @@ bug-reports: "https://github.com/futurGH/pegasus/issues" depends: [ "ocaml" "dune" {>= "3.14"} + "lwt" + "re" {>= "1.13.2"} + "yojson" {>= "3.0.0"} + "lwt_ppx" {>= "5.9.1"} + "ppx_deriving_yojson" {>= "3.9.1"} + "alcotest" {with-test} "odoc" {with-doc} ] build: [ diff --git a/pegasus/lib/dune b/pegasus/lib/dune index 544b1a9..e1c3c35 100644 --- a/pegasus/lib/dune +++ b/pegasus/lib/dune @@ -1,2 +1,16 @@ (library - (name pegasus)) + (name pegasus) + (libraries + ipld + lwt + lwt.unix + mist + re + str + yojson + lwt_ppx + ppx_deriving_yojson.runtime) + (preprocess + (pps lwt_ppx ppx_deriving_yojson))) + +(include_subdirs qualified) diff --git a/mist/lib/repository.ml b/pegasus/lib/repository.ml similarity index 75% rename from mist/lib/repository.ml rename to pegasus/lib/repository.ml index bbb44cc..6a7619e 100644 --- a/mist/lib/repository.ml +++ b/pegasus/lib/repository.ml @@ -1,3 +1,5 @@ +open Mist + type commit = { did: string ; version: int (* always 3 *) @@ -36,13 +38,5 @@ type signed_commit = type signing_key = P256 of bytes | K256 of bytes module Make (Store : Storage.Writable_blockstore) = struct - type store = Store.t - - let read_commit store cid : (signed_commit, string) Lwt_result.t = - let%lwt bytes = Store.get_bytes store cid in - match bytes with - | Some b -> - b |> Dag_cbor.decode_to_yojson |> signed_commit_of_yojson |> Lwt.return - | None -> - Lwt.return_error ("commit not found in blockstore: " ^ Cid.to_string cid) + type t = {store: Store.t; key: signing_key} end