plc

package
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2026 License: Apache-2.0, MIT Imports: 20 Imported by: 1

Documentation

Overview

Package plc provides a client for the DID PLC directory.

DID PLC is the primary DID method in ATProto. The PLC directory stores a chain of signed operations declaring each DID's signing keys, rotation keys, handle, and PDS endpoint.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotSigned is returned when an operation requires a signature but has none.
	ErrNotSigned = errors.New("plc: operation is not signed")
	// ErrNotFound is returned when a DID does not exist in the PLC directory.
	ErrNotFound = errors.New("plc: DID not found")
)

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is an HTTP client for the PLC directory. Safe for concurrent use.

func NewClient

func NewClient(cfg ClientConfig) *Client

NewClient creates a new PLC client. Zero-value ClientConfig uses sensible defaults.

func (*Client) AuditLog

func (c *Client) AuditLog(ctx context.Context, did atmos.DID) ([]LogEntry, error)

AuditLog returns all operations including nullified, with metadata.

func (*Client) OpLog

func (c *Client) OpLog(ctx context.Context, did atmos.DID) ([]json.RawMessage, error)

OpLog returns active (non-nullified) operations as raw JSON.

func (*Client) Resolve

func (c *Client) Resolve(ctx context.Context, did atmos.DID) (*identity.DIDDocument, error)

Resolve fetches the current DID document.

func (*Client) Submit

func (c *Client) Submit(ctx context.Context, did atmos.DID, op any) error

Submit sends a signed operation (Operation or TombstoneOp) to the directory.

type ClientConfig

type ClientConfig struct {
	DirectoryURL gt.Option[string]
	HTTPClient   gt.Option[*http.Client]
	UserAgent    gt.Option[string]
}

ClientConfig holds optional configuration for a PLC client.

type CreateParams

type CreateParams struct {
	SigningKey   crypto.PrivateKey
	RotationKeys []crypto.PublicKey
	Handle       atmos.Handle
	PDS          string
}

CreateParams holds the parameters for creating a new DID.

type LogEntry

type LogEntry struct {
	DID       string          `json:"did"`
	Operation json.RawMessage `json:"operation"`
	CID       string          `json:"cid"`
	Nullified bool            `json:"nullified"`
	CreatedAt string          `json:"createdAt"`
}

LogEntry is a single entry from the audit log.

type Operation

type Operation struct {
	Type                string             `json:"type"`
	RotationKeys        []string           `json:"rotationKeys"`
	VerificationMethods map[string]string  `json:"verificationMethods"`
	AlsoKnownAs         []string           `json:"alsoKnownAs"`
	Services            map[string]Service `json:"services"`
	Prev                *string            `json:"prev"`
	Sig                 *string            `json:"sig,omitempty"`
}

Operation is a PLC operation (plc_operation type).

func CreateDID

func CreateDID(params CreateParams) (*Operation, atmos.DID, error)

CreateDID builds, signs, and returns a genesis operation and computed DID.

func UpdateOp

func UpdateOp(prev *Operation, prevCID string, params UpdateParams) *Operation

UpdateOp builds an update operation from the previous operation. Fields in params that are nil are inherited (copied) from prev.

func (*Operation) CID

func (op *Operation) CID() (string, error)

CID computes the CID of the signed operation (dag-cbor, sha-256).

func (*Operation) DID

func (op *Operation) DID() (atmos.DID, error)

DID computes the did:plc: identifier from a signed genesis operation. The signed CBOR bytes are SHA-256 hashed, base32-lower encoded, and truncated to 24 characters.

func (*Operation) Doc

func (op *Operation) Doc(did atmos.DID) *identity.DIDDocument

Doc converts the operation to a DID document. Keys that fail to parse are silently omitted, matching PLC directory behavior.

func (*Operation) Sign

func (op *Operation) Sign(key crypto.PrivateKey) error

Sign signs the operation with the given rotation key.

func (*Operation) SignedBytes

func (op *Operation) SignedBytes() ([]byte, error)

SignedBytes returns the DAG-CBOR encoding with sig included.

func (*Operation) UnsignedBytes

func (op *Operation) UnsignedBytes() ([]byte, error)

UnsignedBytes returns the DAG-CBOR encoding with sig omitted (for signing).

func (*Operation) Verify

func (op *Operation) Verify(key crypto.PublicKey) error

Verify checks the signature against a public key.

type Service

type Service struct {
	Type     string `json:"type"`
	Endpoint string `json:"endpoint"`
}

Service is a service entry in a PLC operation.

type TombstoneOp

type TombstoneOp struct {
	Type string  `json:"type"`
	Prev string  `json:"prev"`
	Sig  *string `json:"sig,omitempty"`
}

TombstoneOp deactivates a DID permanently.

func NewTombstoneOp

func NewTombstoneOp(prevCID string) *TombstoneOp

NewTombstoneOp builds a tombstone operation.

func (*TombstoneOp) Sign

func (t *TombstoneOp) Sign(key crypto.PrivateKey) error

Sign signs the tombstone with the given rotation key.

func (*TombstoneOp) SignedBytes

func (t *TombstoneOp) SignedBytes() ([]byte, error)

SignedBytes returns the DAG-CBOR encoding of a tombstone with sig included.

func (*TombstoneOp) UnsignedBytes

func (t *TombstoneOp) UnsignedBytes() ([]byte, error)

UnsignedBytes returns the DAG-CBOR encoding of a tombstone with sig omitted.

func (*TombstoneOp) Verify

func (t *TombstoneOp) Verify(key crypto.PublicKey) error

Verify checks the tombstone signature against a public key.

type UpdateParams

type UpdateParams struct {
	VerificationMethods map[string]string
	RotationKeys        []string
	AlsoKnownAs         []string
	Services            map[string]Service
}

UpdateParams holds the parameters for updating a DID operation. Nil fields are inherited from the previous operation.

Jump to

Keyboard shortcuts

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