atproto libraries implementation in ocaml
at main 1.7 kB view raw
1(** AT Protocol Repository Support. 2 3 This package provides repository operations for AT Protocol including: 4 5 - {!module:Commit}: Commit creation, signing, and verification 6 - {!module:Repo}: Repository structure with MST-backed record storage 7 8 {2 Repository Structure} 9 10 An AT Protocol repository contains: 11 - A DID identifying the repository owner 12 - A signed commit with the current state 13 - An MST (Merkle Search Tree) containing all records 14 - Records organized by collection (NSID) and record key 15 16 {2 Commit Example} 17 18 {[ 19 open Atproto_repo 20 21 (* Create and sign a commit *) 22 let commit = Commit.create 23 ~did:"did:plc:xyz" 24 ~prev:(Some prev_cid) 25 ~data:mst_root_cid 26 ~rev:"2024010112345" 27 in 28 let signed = Commit.sign commit keypair in 29 30 (* Verify a commit *) 31 match Commit.verify signed public_key with 32 | Ok () -> print_endline "Valid commit" 33 | Error e -> print_endline ("Invalid: " ^ e) 34 ]} 35 36 {2 Repository Operations} 37 38 {[ 39 open Atproto_repo 40 41 (* Create a new repository *) 42 let repo = Repo.create ~did:"did:plc:xyz" in 43 44 (* Add a record *) 45 let record = `Assoc [("text", `String "Hello!")] in 46 let repo = Repo.put repo 47 ~collection:"app.bsky.feed.post" 48 ~rkey:"abc123" 49 ~record 50 in 51 52 (* Get a record *) 53 match Repo.get repo ~collection:"app.bsky.feed.post" ~rkey:"abc123" with 54 | Some record -> (* ... *) 55 | None -> (* ... *) 56 ]} 57 58 @see <https://atproto.com/specs/repository> Repository specification *) 59 60module Commit = Commit 61module Repo = Repo