reputation

package
v1.1.13 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2026 License: AGPL-3.0 Imports: 29 Imported by: 0

Documentation

Overview

Package reputation provides actor reputation calculation algorithms based on activity history and trust metrics.

Index

Constants

View Source
const (
	OutcomeUpheld    = "upheld"
	OutcomeDismissed = "dismissed"
	OutcomePending   = "pending"
)

Moderation outcome constants

Variables

This section is empty.

Functions

This section is empty.

Types

type CalculationInput

type CalculationInput struct {
	ActorID string

	// Activity metrics
	PostCount      int
	FollowerCount  int
	FollowingCount int
	AccountCreated time.Time
	LastActive     time.Time

	// Trust graph data
	TrustRelationships []TrustRelationship

	// Moderation data
	ModerationHistory []ModerationEvent

	// Vouch data
	VouchesReceived []Vouch
	VouchesGiven    []Vouch

	// Community contributions
	CommunityNotes int
	HelpfulVotes   int
}

CalculationInput contains all data needed to calculate reputation

type Calculator

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

Calculator computes reputation scores for actors

func NewCalculator

func NewCalculator(store core.RepositoryStorage, instanceURL string, logger *zap.Logger) *Calculator

NewCalculator creates a new reputation calculator

func (*Calculator) Calculate

func (c *Calculator) Calculate(_ context.Context, input *CalculationInput) (*Reputation, error)

Calculate computes a reputation score for an actor

func (*Calculator) GetBoostFromVouches

func (c *Calculator) GetBoostFromVouches(vouches []Vouch) int

GetBoostFromVouches calculates initial reputation boost from vouches

type Config

type Config struct {
	Storage     core.RepositoryStorage
	Logger      *zap.Logger
	CostTracker *cost.Tracker
	InstanceURL string
	PrivateKey  string
}

Config contains configuration for the reputation service

type CreateVouchInput

type CreateVouchInput struct {
	FromActorID string
	ToActorID   string
	Confidence  float64
	Context     string
}

CreateVouchInput contains the parameters for creating a vouch

type ImportResult

type ImportResult struct {
	Success         bool   `json:"success"`
	ActorID         string `json:"actorId"`
	PreviousScore   int    `json:"previousScore"`
	ImportedScore   int    `json:"importedScore"`
	VouchesImported int    `json:"vouchesImported"`
	Message         string `json:"message,omitempty"`
	Error           string `json:"error,omitempty"`
}

ImportResult represents the result of importing reputation

type ModerationEvent

type ModerationEvent struct {
	ID         string
	Type       string // "report", "suspension", "appeal"
	Outcome    string // "upheld", "dismissed", "pending"
	Severity   int
	OccurredAt time.Time
}

ModerationEvent represents a moderation action

type PortableReputation

type PortableReputation struct {
	Context    []string    `json:"@context"`
	Type       string      `json:"@type"`
	Actor      string      `json:"actor"`
	Reputation *Reputation `json:"reputation"`
	Vouches    []Vouch     `json:"vouches"`
	IssuedAt   time.Time   `json:"issuedAt"`
	ExpiresAt  time.Time   `json:"expiresAt"`

	// Instance attestation
	Issuer      string `json:"issuer"`
	IssuerProof string `json:"issuerProof"`
}

PortableReputation is the exportable reputation document

type Reputation

type Reputation struct {
	// Identity
	ActorID     string `json:"@id" dynamodbav:"ActorID"`
	InstanceURL string `json:"instance" dynamodbav:"InstanceURL"`

	// Scores (0-1000 scale)
	TrustScore      int `json:"trustScore" dynamodbav:"TrustScore"`
	ActivityScore   int `json:"activityScore" dynamodbav:"ActivityScore"`
	ModerationScore int `json:"moderationScore" dynamodbav:"ModerationScore"`
	CommunityScore  int `json:"communityScore" dynamodbav:"CommunityScore"`
	TotalScore      int `json:"totalScore" dynamodbav:"TotalScore"`

	// Metadata
	CalculatedAt time.Time `json:"calculatedAt" dynamodbav:"CalculatedAt"`
	Version      string    `json:"version" dynamodbav:"Version"`

	// Evidence
	TotalPosts     int `json:"totalPosts" dynamodbav:"TotalPosts"`
	TotalFollowers int `json:"totalFollowers" dynamodbav:"TotalFollowers"`
	AccountAge     int `json:"accountAgeDays" dynamodbav:"AccountAge"`
	VouchCount     int `json:"vouchCount" dynamodbav:"VouchCount"`

	// Trust graph metrics
	TrustingActors    int     `json:"trustingActors" dynamodbav:"TrustingActors"`
	AverageTrustScore float64 `json:"averageTrustScore" dynamodbav:"AverageTrustScore"`

	// Moderation metrics
	ReportsReceived int `json:"reportsReceived" dynamodbav:"ReportsReceived"`
	ReportsUpheld   int `json:"reportsUpheld" dynamodbav:"ReportsUpheld"`
	FalseReports    int `json:"falseReports" dynamodbav:"FalseReports"`

	// Cryptographic proof
	Signature string `json:"signature,omitempty" dynamodbav:"Signature,omitempty"`
	PublicKey string `json:"publicKey,omitempty" dynamodbav:"PublicKey,omitempty"`
}

Reputation represents a user's reputation score and evidence

type Service

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

Service provides reputation management functionality

func NewService

func NewService(cfg *Config) (*Service, error)

NewService creates a new reputation service

func (*Service) CreateVouch

func (s *Service) CreateVouch(ctx context.Context, fromActorID, toActorID string, confidence float64, context string) (*Vouch, error)

CreateVouch creates a new vouch

func (*Service) ExportReputation

func (s *Service) ExportReputation(ctx context.Context, actorID string) (*PortableReputation, error)

ExportReputation exports a portable reputation document

func (*Service) GetPublicKey

func (s *Service) GetPublicKey() string

GetPublicKey returns the instance's public key for reputation signing

func (*Service) GetReputation

func (s *Service) GetReputation(ctx context.Context, actorID string) (*Reputation, error)

GetReputation retrieves the current reputation for an actor

func (*Service) GetVouches

func (s *Service) GetVouches(ctx context.Context, actorID string) ([]Vouch, error)

GetVouches retrieves vouches for an actor

func (*Service) ImportReputation

func (s *Service) ImportReputation(ctx context.Context, document string) (*ImportResult, error)

ImportReputation imports a portable reputation document

func (*Service) RevokeVouch

func (s *Service) RevokeVouch(ctx context.Context, vouchID, actorID string) error

RevokeVouch revokes an existing vouch

func (*Service) VerifyReputation

func (s *Service) VerifyReputation(_ context.Context, document string) (*VerificationResult, error)

VerifyReputation verifies a reputation document

type Signer

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

Signer handles cryptographic signing of reputation documents

func NewSigner

func NewSigner(privateKeyPEM string, instanceURL string, logger *zap.Logger) (*Signer, error)

NewSigner creates a new reputation signer

func (*Signer) GetPublicKeyBase64

func (s *Signer) GetPublicKeyBase64() string

GetPublicKeyBase64 returns the base64-encoded public key

func (*Signer) SignPortableReputation

func (s *Signer) SignPortableReputation(pr *PortableReputation) error

SignPortableReputation signs a complete portable reputation document

func (*Signer) SignReputation

func (s *Signer) SignReputation(rep *Reputation) error

SignReputation signs a reputation document

func (*Signer) SignVouch

func (s *Signer) SignVouch(vouch *Vouch) error

SignVouch signs a vouch document

type TrustRelationship

type TrustRelationship struct {
	FromActor  string
	ToActor    string
	TrustScore float64
	Category   string
	UpdatedAt  time.Time
}

TrustRelationship represents a trust connection

type VerificationResult

type VerificationResult struct {
	Valid          bool      `json:"valid"`
	ActorID        string    `json:"actorId"`
	Issuer         string    `json:"issuer"`
	IssuedAt       time.Time `json:"issuedAt"`
	ExpiresAt      time.Time `json:"expiresAt"`
	SignatureValid bool      `json:"signatureValid"`
	NotExpired     bool      `json:"notExpired"`
	IssuerTrusted  bool      `json:"issuerTrusted"`
	Error          string    `json:"error,omitempty"`
}

VerificationResult represents the result of verifying a reputation document

type Verifier

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

Verifier handles verification of reputation documents

func NewVerifier

func NewVerifier(instanceURL string, logger *zap.Logger, domainTrust domainTrustRepository) *Verifier

NewVerifier creates a new reputation verifier

func (*Verifier) VerifyPortableReputation

func (v *Verifier) VerifyPortableReputation(pr *PortableReputation) (*VerificationResult, error)

VerifyPortableReputation verifies a complete portable reputation document

func (*Verifier) VerifyReputation

func (v *Verifier) VerifyReputation(rep *Reputation) (bool, error)

VerifyReputation verifies a reputation document's signature

func (*Verifier) VerifyVouchSignature

func (v *Verifier) VerifyVouchSignature(vouch *Vouch) (bool, error)

VerifyVouchSignature verifies a vouch's signature using the issuer's public key

type Vouch

type Vouch struct {
	ID          string    `json:"@id" dynamodbav:"ID"`
	From        string    `json:"from" dynamodbav:"From"` // Actor who vouched
	To          string    `json:"to" dynamodbav:"To"`     // Actor being vouched for
	InstanceURL string    `json:"instance" dynamodbav:"InstanceURL"`
	CreatedAt   time.Time `json:"createdAt" dynamodbav:"CreatedAt"`
	ExpiresAt   time.Time `json:"expiresAt" dynamodbav:"ExpiresAt"`
	Confidence  float64   `json:"confidence" dynamodbav:"Confidence"` // 0.0-1.0
	Context     string    `json:"context" dynamodbav:"Context"`       // Why vouching

	// Voucher reputation at time of vouch
	VoucherReputation int `json:"voucherReputation" dynamodbav:"VoucherReputation"`

	// Status
	Active    bool       `json:"active" dynamodbav:"Active"`
	Revoked   bool       `json:"revoked" dynamodbav:"Revoked"`
	RevokedAt *time.Time `json:"revokedAt,omitempty" dynamodbav:"RevokedAt,omitempty"`

	// Cryptographic proof
	Signature string `json:"signature" dynamodbav:"Signature"`
}

Vouch represents one user vouching for another

type VouchManager

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

VouchManager handles vouch creation and management

func NewVouchManager

func NewVouchManager(store core.RepositoryStorage, signer *Signer, instanceURL string, logger *zap.Logger) *VouchManager

NewVouchManager creates a new vouch manager

func (*VouchManager) CreateVouch

func (vm *VouchManager) CreateVouch(ctx context.Context, input *CreateVouchInput) (*Vouch, error)

CreateVouch creates a new vouch

func (*VouchManager) GetVouchByID

func (vm *VouchManager) GetVouchByID(ctx context.Context, vouchID string) (*Vouch, error)

GetVouchByID retrieves a vouch by ID

func (*VouchManager) GetVouchesForActor

func (vm *VouchManager) GetVouchesForActor(ctx context.Context, actorID string) ([]Vouch, error)

GetVouchesForActor gets all vouches for an actor

func (*VouchManager) GetVouchesFromActor

func (vm *VouchManager) GetVouchesFromActor(ctx context.Context, actorID string) ([]Vouch, error)

GetVouchesFromActor gets all vouches created by an actor

func (*VouchManager) ImportVouch

func (vm *VouchManager) ImportVouch(ctx context.Context, vouch *Vouch, verifier vouchSignatureVerifier) error

ImportVouch imports a vouch from another instance

func (*VouchManager) ImportVouches

func (vm *VouchManager) ImportVouches(ctx context.Context, vouches []Vouch, verifier vouchSignatureVerifier) (int, error)

ImportVouches imports multiple vouches in batch

func (*VouchManager) RevokeVouch

func (vm *VouchManager) RevokeVouch(ctx context.Context, vouchID string, actorID string) error

RevokeVouch revokes an existing vouch

Jump to

Keyboard shortcuts

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