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 ¶
- Variables
- type Client
- func (c *Client) AuditLog(ctx context.Context, did atmos.DID) ([]LogEntry, error)
- func (c *Client) OpLog(ctx context.Context, did atmos.DID) ([]json.RawMessage, error)
- func (c *Client) Resolve(ctx context.Context, did atmos.DID) (*identity.DIDDocument, error)
- func (c *Client) Submit(ctx context.Context, did atmos.DID, op any) error
- type ClientConfig
- type CreateParams
- type LogEntry
- type Operation
- func (op *Operation) CID() (string, error)
- func (op *Operation) DID() (atmos.DID, error)
- func (op *Operation) Doc(did atmos.DID) *identity.DIDDocument
- func (op *Operation) Sign(key crypto.PrivateKey) error
- func (op *Operation) SignedBytes() ([]byte, error)
- func (op *Operation) UnsignedBytes() ([]byte, error)
- func (op *Operation) Verify(key crypto.PublicKey) error
- type Service
- type TombstoneOp
- type UpdateParams
Constants ¶
This section is empty.
Variables ¶
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.
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) DID ¶
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 ¶
SignedBytes returns the DAG-CBOR encoding with sig included.
func (*Operation) UnsignedBytes ¶
UnsignedBytes returns the DAG-CBOR encoding with sig omitted (for signing).
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.