Exosphere.ATProto.Repo (Exosphere v0.5.0)

Copy Markdown View Source

Exosphere.ATProto repository operations for writing records to a user's PDS.

This module handles authenticated writes to the user's Exosphere.ATProto repository using OAuth tokens and DPoP proofs.

Summary

Functions

Create a new record in the user's repository.

Delete a record from the user's repository.

Get a record from any repository (public, no auth needed).

Put (create or update) a record in the user's repository.

Fetch a repository from a PDS as a CAR archive and fully verify it.

Functions

create_record(session, pds_url, did, collection, record)

Create a new record in the user's repository.

Uses com.atproto.repo.createRecord for records with auto-generated keys.

Parameters

  • session - OAuth session with access_token and dpop_private_key
  • pds_url - URL of the user's PDS
  • did - The user's DID
  • collection - The collection NSID
  • record - The record data to write

Returns

  • {:ok, %{uri: uri, cid: cid}} on success
  • {:error, reason} on failure

delete_record(session, pds_url, did, collection, rkey)

Delete a record from the user's repository.

Parameters

  • session - OAuth session
  • pds_url - URL of the user's PDS
  • did - The user's DID
  • collection - The collection NSID
  • rkey - The record key to delete

get_record(pds_url, did, collection, rkey)

Get a record from any repository (public, no auth needed).

put_record(session, pds_url, did, collection, rkey, record)

Put (create or update) a record in the user's repository.

Uses com.atproto.repo.putRecord for records with known keys (like profile with "self").

Parameters

  • session - an %Exosphere.ATProto.OAuth.Session{} (or a map with access_token and a base64-encoded JSON JWK under dpop_private_key)
  • pds_url - URL of the user's PDS
  • did - The user's DID
  • collection - The collection NSID (e.g., "app.bsky.actor.profile")
  • rkey - The record key (e.g., "self")
  • record - The record data to write

Returns

  • {:ok, %{uri: uri, cid: cid}} on success
  • {:error, reason} on failure

verify_checkout(pds_url, did, opts \\ [])

@spec verify_checkout(String.t(), Exosphere.ATProto.Identity.DID.did(), keyword()) ::
  {:ok,
   %{
     did: Exosphere.ATProto.Identity.DID.did(),
     rev: String.t() | nil,
     commit: Exosphere.ATProto.CID.t(),
     records: map()
   }}
  | {:error, term()}

Fetch a repository from a PDS as a CAR archive and fully verify it.

Downloads com.atproto.sync.getRepo, reads the record set out of the returned MST, checks it against the commit's signed root (Repo.Commit.verify_checkout/2), resolves the repo's DID document, and verifies the commit signature (Repo.Commit.verify/3).

This is the trustless read path: rather than trusting the PDS's getRecord responses, the whole repository is checked against the key the account advertises in its DID document.

Parameters

  • pds_url - Base URL of the PDS (e.g. "https://bsky.social")
  • did - The repository's DID
  • opts - Options:
    • :verify_signature - When false, skip DID resolution and signature verification (default: true)
    • :http - HTTP client module implementing HTTP.Behaviour (default: HTTP; useful for testing)
    • :did_document - A pre-resolved %Identity.Document{} to verify against, skipping DID resolution (useful for testing)

Returns

  • {:ok, %{did: did, rev: rev, commit: %CID{}, records: %{path => %CID{}}}}
  • {:error, reason} — network errors, malformed CAR, MST/root mismatches, or signature failures