peer

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateProjectID

func GenerateProjectID() (string, error)

GenerateProjectID creates a stable random project identifier for a repository.

func SaveProjectConfig

func SaveProjectConfig(pc *ProjectConfig) error

SaveProjectConfig writes .devcontract.toml in the current directory.

Types

type IntegrityIssue

type IntegrityIssue struct {
	Path   string
	Detail string
}

type Peer

type Peer struct {
	// DisplayName is the human-facing label for the peer.
	DisplayName string `toml:"display_name,omitempty"`

	// LegacyGitHubUsername keeps older peer files readable.
	LegacyGitHubUsername string `toml:"github_username,omitempty"`

	// RelayUsername is the relay-side member name used for display.
	RelayUsername string `toml:"relay_username,omitempty"`

	// Fingerprint is the Ed25519 identity fingerprint (SHA256:...).
	Fingerprint string `toml:"fingerprint"`

	// Ed25519Public is the identity public key (base64).
	Ed25519Public string `toml:"ed25519_public,omitempty"`

	// X25519Public is the transport public key (base64).
	X25519Public string `toml:"x25519_public,omitempty"`

	// TransportFingerprint is the fingerprint of the X25519 transport key.
	TransportFingerprint string `toml:"transport_fingerprint,omitempty"`

	// DeviceName is an optional human-readable device label.
	DeviceName string `toml:"device_name,omitempty"`

	// Trust is the current trust state.
	Trust TrustState `toml:"trust"`

	// FirstSeen is when this peer was first encountered.
	FirstSeen time.Time `toml:"first_seen"`

	// LastSeen is the last successful sync with this peer.
	LastSeen time.Time `toml:"last_seen"`

	// TrustedAt is when the peer was explicitly trusted.
	TrustedAt time.Time `toml:"trusted_at,omitempty"`

	// RevokedAt is when the peer was revoked.
	RevokedAt time.Time `toml:"revoked_at,omitempty"`
}

Peer represents a known peer in the registry.

func (*Peer) CanSync

func (p *Peer) CanSync() bool

CanSync returns true if this peer is trusted and can participate in sync.

func (*Peer) EffectiveTransportFingerprint

func (p *Peer) EffectiveTransportFingerprint() string

EffectiveTransportFingerprint returns the fingerprint used for transport verification.

func (*Peer) IsRevoked

func (p *Peer) IsRevoked() bool

IsRevoked returns true if this peer is revoked.

func (*Peer) MatchesTransportPublicKey

func (p *Peer) MatchesTransportPublicKey(publicKey []byte) bool

MatchesTransportPublicKey returns true if the provided key matches the stored transport identity.

func (*Peer) Normalize

func (p *Peer) Normalize()

Normalize keeps compatibility with older peer files while writing the canonical display_name field for current builds.

func (*Peer) PromoteToTrusted

func (p *Peer) PromoteToTrusted() error

PromoteToTrusted moves the peer from pending to trusted.

func (*Peer) Revoke

func (p *Peer) Revoke() error

Revoke moves the peer to revoked state.

func (*Peer) StatusIcon

func (p *Peer) StatusIcon() string

StatusIcon returns a visual indicator for the peer's trust state.

func (*Peer) TransportPublicKeyBytes

func (p *Peer) TransportPublicKeyBytes() ([]byte, error)

TransportPublicKeyBytes decodes the stored X25519 public key.

func (*Peer) Validate

func (p *Peer) Validate() error

Validate checks if a peer's data is valid.

type ProjectConfig

type ProjectConfig struct {
	ConfigVersion int    `toml:"config_version,omitempty"`
	ProjectID     string `toml:"project_id,omitempty"`
	LegacyTeamID  string `toml:"team_id,omitempty"`
	Name          string `toml:"name,omitempty"`
	DefaultFile   string `toml:"default_file,omitempty"`
	SyncStrategy  string `toml:"sync_strategy,omitempty"`
	RelayURL      string `toml:"relay_url,omitempty"`
}

ProjectConfig represents the per-project .devcontract.toml file.

func LoadProjectConfig

func LoadProjectConfig() (*ProjectConfig, error)

LoadProjectConfig reads the .devcontract.toml from the current (or parent) directory.

func NewProjectConfig

func NewProjectConfig(name, defaultFile, syncStrategy, relayURL string) (*ProjectConfig, error)

NewProjectConfig creates a fresh per-project config with a stable project ID.

func (*ProjectConfig) CanonicalProjectID

func (pc *ProjectConfig) CanonicalProjectID() string

CanonicalProjectID returns the single project/team ID used throughout the CLI.

func (*ProjectConfig) Normalize

func (pc *ProjectConfig) Normalize()

Normalize backfills defaults and migrates legacy team_id data into project_id.

type Registry

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

Registry manages the persistent store of known peers and teams.

func NewRegistry

func NewRegistry() (*Registry, error)

NewRegistry creates a new peer registry backed by the filesystem.

func (*Registry) DeletePeer

func (r *Registry) DeletePeer(teamID, fingerprint string) error

DeletePeer removes a peer from a team.

func (*Registry) FindPeerByLabel

func (r *Registry) FindPeerByLabel(label string) (*Peer, string, error)

FindPeerByLabel searches all projects for a peer with the given display label.

func (*Registry) FindPeerInTeam

func (r *Registry) FindPeerInTeam(teamID, selector string) (*Peer, error)

FindPeerInTeam resolves a member by exact fingerprint, relay username, or display label within one project.

func (*Registry) ListPeers

func (r *Registry) ListPeers(teamID string) ([]Peer, error)

ListPeers returns all peers in a team and fails if any peer file is unreadable or malformed.

func (*Registry) ListTeams

func (r *Registry) ListTeams() ([]string, error)

ListTeams returns all known team IDs.

func (*Registry) LoadPeer

func (r *Registry) LoadPeer(teamID, fingerprint string) (*Peer, error)

LoadPeer loads a specific peer from a team.

func (*Registry) LoadTeam

func (r *Registry) LoadTeam(teamID string) (*Team, error)

LoadTeam loads a team from disk.

func (*Registry) SavePeer

func (r *Registry) SavePeer(teamID string, p *Peer) error

SavePeer persists a peer within a team.

func (*Registry) SaveTeam

func (r *Registry) SaveTeam(team *Team) error

SaveTeam persists a team to disk.

func (*Registry) ScanIntegrity

func (r *Registry) ScanIntegrity(teamID string) ([]IntegrityIssue, error)

ScanIntegrity reports unreadable or malformed registry files without loading them into active state.

type Team

type Team struct {
	// ID is a unique team identifier.
	ID string `toml:"id"`

	// Name is a human-readable team name.
	Name string `toml:"name"`

	// CreatedBy is the identity fingerprint of the team creator.
	CreatedBy string `toml:"created_by"`

	// CreatedAt is when the team was created.
	CreatedAt time.Time `toml:"created_at"`

	// Members is the list of identity fingerprints in this team.
	Members []string `toml:"members"`
}

Team represents a team of peers sharing .env files.

func (*Team) AddMember

func (t *Team) AddMember(fingerprint string)

AddMember adds a fingerprint to the team's member list.

func (*Team) HasMember

func (t *Team) HasMember(fingerprint string) bool

HasMember checks if a fingerprint is in the team.

func (*Team) RemoveMember

func (t *Team) RemoveMember(fingerprint string)

RemoveMember removes a fingerprint from the team's member list.

type TrustState

type TrustState string

TrustState represents the trust level of a peer.

const (
	TrustUnknown TrustState = "unknown"
	TrustPending TrustState = "pending"
	TrustTrusted TrustState = "trusted"
	TrustRevoked TrustState = "revoked"
)

Jump to

Keyboard shortcuts

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