atproto

package
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 22, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CollectionActivity        = "org.hypercerts.claim.activity"
	CollectionContributorInfo = "org.hypercerts.claim.contributorInformation"
	CollectionMeasurement     = "org.hypercerts.claim.measurement"
	CollectionAttachment      = "org.hypercerts.claim.attachment"
	CollectionCollection      = "org.hypercerts.claim.collection"
	CollectionEvaluation      = "org.hypercerts.claim.evaluation"
	CollectionRights          = "org.hypercerts.claim.rights"
	CollectionFundingReceipt  = "org.hypercerts.funding.receipt"
	CollectionWorkScopeTag    = "org.hypercerts.helper.workScopeTag"
	CollectionLocation        = "app.certified.location"
)

ATProto collection NSIDs for Hypercerts record types.

View Source
const ConstellationBase = "https://constellation.microcosm.blue"

Variables

View Source
var ErrNoAuthSession = errors.New("no auth session found")

ErrNoAuthSession is returned when no auth session file is found.

Functions

func ConfigDirectory

func ConfigDirectory(plcHost, version string) identity.Directory

ConfigDirectory returns an identity directory configured with PLC host and user agent.

func CreateRecord

func CreateRecord(ctx context.Context, client *atclient.APIClient, collection string, record map[string]any) (uri, cid string, err error)

CreateRecord creates a new record in the given collection. Always sets Validate: false for custom unpublished lexicons.

func DeleteRecord

func DeleteRecord(ctx context.Context, client *atclient.APIClient, did, collection, rkey string) error

DeleteRecord deletes a record by DID, collection, and record key.

func ExtractRkey

func ExtractRkey(uri string) string

ExtractRkey extracts the record key (last segment) from an AT-URI.

func GetRecord

func GetRecord(ctx context.Context, client *atclient.APIClient, did, collection, rkey string) (map[string]any, string, error)

GetRecord fetches a single record by DID, collection, and record key. Returns the record value, CID, and error.

func LoadAuthClient

func LoadAuthClient(ctx context.Context, plcHost, version string) (*atclient.APIClient, error)

LoadAuthClient loads an auth client from the saved session.

func Login

func Login(ctx context.Context, username, password, pdsHost, plcHost, version string) (*atclient.APIClient, error)

Login authenticates with a PDS using username and password.

func LoginOrLoad

func LoginOrLoad(ctx context.Context, username, password, plcHost, version string) (*atclient.APIClient, error)

LoginOrLoad checks for username/password first, then falls back to loading a saved session.

func PersistAuthSession

func PersistAuthSession(sess *AuthSession) error

PersistAuthSession saves the auth session to XDG state directory.

func PutRecord

func PutRecord(ctx context.Context, client *atclient.APIClient, did, collection, rkey string, record map[string]any, swapCID *string) (string, error)

PutRecord updates an existing record with optimistic concurrency via swapCID.

func WipeAuthSession

func WipeAuthSession() error

WipeAuthSession deletes the auth session file.

Types

type AuthSession

type AuthSession struct {
	DID          syntax.DID `json:"did"`
	PDS          string     `json:"pds"`
	Handle       string     `json:"handle"`
	Password     string     `json:"password"`
	AccessToken  string     `json:"access_token"`
	RefreshToken string     `json:"refresh_token"`
}

AuthSession stores the authentication state. WARNING: The app password is stored in plaintext at ~/.local/state/hc/auth-session.json with 0600 permissions. This is required for automatic token refresh. Users should use ATProto app passwords (not their main password). TODO: Consider OS keychain integration for password storage.

func LoadAuthSessionFile

func LoadAuthSessionFile() (*AuthSession, error)

LoadAuthSessionFile loads the auth session from XDG state directory.

type BacklinkCounts

type BacklinkCounts struct {
	Records      int `json:"records"`
	DistinctDIDs int `json:"distinct_dids"`
}

BacklinkCounts is the count of records and distinct DIDs for a specific collection+path.

type BacklinksResponse

type BacklinksResponse struct {
	Total          int             `json:"total"`
	Cursor         *string         `json:"cursor"`
	LinkingRecords []LinkingRecord `json:"linking_records"`
}

BacklinksResponse is the response from /links (paginated).

func GetBacklinks(ctx context.Context, target, collection, path string, cursor string, limit int) (*BacklinksResponse, error)

GetBacklinks returns a paginated list of records linking to the target for a specific collection and path.

type BacklinksSummary

type BacklinksSummary struct {
	Links map[string]map[string]BacklinkCounts `json:"links"`
}

BacklinksSummary is the response from /links/all.

func GetAllBacklinks(ctx context.Context, target string) (*BacklinksSummary, error)

GetAllBacklinks returns a summary of all records linking to the target (DID or AT-URI).

type LinkingRecord

type LinkingRecord struct {
	DID        string `json:"did"`
	Collection string `json:"collection"`
	Rkey       string `json:"rkey"`
}

LinkingRecord is a single record that links to the target.

func GetAllBacklinkRecords

func GetAllBacklinkRecords(ctx context.Context, target, collection, path string) ([]LinkingRecord, error)

GetAllBacklinkRecords fetches all linking records for a target+collection+path, handling pagination.

type RecordEntry

type RecordEntry struct {
	URI   string
	CID   string
	Value map[string]any
}

RecordEntry represents a single record from a listing.

func ListAllRecords

func ListAllRecords(ctx context.Context, client *atclient.APIClient, did, collection string) ([]RecordEntry, error)

ListAllRecords fetches all records in a collection with cursor-based pagination.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL