Documentation
¶
Overview ¶
Implementation of atproto repository and sync APIs, built on the MST data structure.
The current package works for processing a sync firehose, including validation of "inductive firehose". It does not yet work for implementing a repository host (PDS).
Index ¶
- Constants
- Variables
- func CheckOp(tree *mst.Tree, op *Operation) error
- func InvertOp(tree *mst.Tree, op *Operation) error
- func LoadFromCAR(ctx context.Context, r io.Reader) (*Commit, *Repo, error)
- func VerifyCommitSignature(ctx context.Context, dir identity.Directory, ...) error
- type Commit
- func (t *Commit) MarshalCBOR(w io.Writer) error
- func (c *Commit) Sign(privkey crypto.PrivateKey) error
- func (t *Commit) UnmarshalCBOR(r io.Reader) (err error)
- func (c *Commit) UnsignedBytes() ([]byte, error)
- func (c *Commit) VerifySignature(pubkey crypto.PublicKey) error
- func (c *Commit) VerifyStructure() error
- type Operation
- type Repo
Constants ¶
const ATPROTO_REPO_VERSION int64 = 3
Version of the repo data format implemented in this package
Variables ¶
var ErrNotFound = errors.New("record not found in repository")
Functions ¶
func VerifyCommitSignature ¶
func VerifyCommitSignature(ctx context.Context, dir identity.Directory, msg *comatproto.SyncSubscribeRepos_Commit) error
temporary/experimental code showing how to verify a commit signature from firehose
TODO: in real implementation, will want to merge this code with `VerifyCommitMessage` above, and have it hanging off some service struct with a configured `identity.Directory`
Types ¶
type Commit ¶
type Commit struct { DID string `json:"did" cborgen:"did"` Version int64 `json:"version" cborgen:"version"` // currently: 3 Prev *cid.Cid `json:"prev" cborgen:"prev"` // NOTE: omitempty would break signature verification for repo v3 Data cid.Cid `json:"data" cborgen:"data"` Sig []byte `json:"sig,omitempty" cborgen:"sig,omitempty"` Rev string `json:"rev,omitempty" cborgen:"rev,omitempty"` }
atproto repo commit object as a struct type. Can be used for direct CBOR or JSON serialization.
func (*Commit) Sign ¶
func (c *Commit) Sign(privkey crypto.PrivateKey) error
Signs the commit, storing the signature in the `Sig` field
func (*Commit) UnsignedBytes ¶
Encodes the commit object as DAG-CBOR, without the signature field. Used for signing or validating signatures.
func (*Commit) VerifySignature ¶
Verifies `Sig` field using the provided key. Returns `nil` if signature is valid.
func (*Commit) VerifyStructure ¶
does basic checks that field values and syntax are correct
type Operation ¶
type Operation struct { // key of the record, eg, '{collection}/{record-key}' Path string // the new record CID value (or nil if this is a deletion) Value *cid.Cid // the previous record CID value (or nil if this is a creation) Prev *cid.Cid }
Metadata about update to a single record (key) in the repo.
Used as an abstraction for creating or validating "commit diffs" (eg, `#commit` firehose events)
func NormalizeOps ¶
re-orders operation list, and checks for duplicates
type Repo ¶
type Repo struct { DID syntax.DID Clock *syntax.TIDClock RecordStore blockstore.Blockstore MST mst.Tree }
High-level wrapper struct for an atproto repository.
func NewEmptyRepo ¶
func VerifyCommitMessage ¶
func VerifyCommitMessage(ctx context.Context, msg *comatproto.SyncSubscribeRepos_Commit) (*Repo, error)
temporary/experimental method to parse and verify a firehose commit message.
TODO: move to a separate 'sync' package? break up in to smaller components?
func (*Repo) Commit ¶
Snapshots the current state of the repository, resulting in a new (unsigned) `Commit` struct.