score

package
v0.0.0-...-21e1f9a Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2025 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AttestationData

type AttestationData struct {
	DID              string    `json:"did"`
	Context          string    `json:"context"`
	Type             string    `json:"type"` // employment, education, etc.
	IssuerDID        string    `json:"issuer_did"`
	IssuerReputation float64   `json:"issuer_reputation"`
	Weight           float64   `json:"weight"`
	Timestamp        time.Time `json:"timestamp"`
	Epoch            int64     `json:"epoch"`
}

AttestationData represents an attestation for scoring

type BatchComputeRequest

type BatchComputeRequest struct {
	Requests []*ComputeRequest `json:"requests"`
}

BatchComputeRequest represents a batch score computation request

type BatchComputeResponse

type BatchComputeResponse struct {
	Responses []*ComputeResponse `json:"responses"`
	Errors    []string           `json:"errors,omitempty"`
}

BatchComputeResponse represents a batch score computation response

type BudgetEnforcer

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

BudgetEnforcer provides higher-level budget enforcement logic

func NewBudgetEnforcer

func NewBudgetEnforcer(manager BudgetManager, config *ScoreConfig) *BudgetEnforcer

NewBudgetEnforcer creates a new budget enforcer

func (*BudgetEnforcer) ClearPenalties

func (e *BudgetEnforcer) ClearPenalties()

ClearPenalties clears reputation penalties (called at epoch boundaries)

func (*BudgetEnforcer) EnforceVouchingLimits

func (e *BudgetEnforcer) EnforceVouchingLimits(ctx context.Context, did, context string, epoch int64, vouchStrength float64) error

EnforceVouchingLimits enforces vouching limits and applies penalties

func (*BudgetEnforcer) GetBudgetUtilization

func (e *BudgetEnforcer) GetBudgetUtilization(ctx context.Context, did, context string, epoch int64) (*BudgetUtilization, error)

GetBudgetUtilization returns budget utilization statistics

func (*BudgetEnforcer) GetReputationPenalty

func (e *BudgetEnforcer) GetReputationPenalty(did string) float64

GetReputationPenalty returns the current reputation penalty for a DID

type BudgetManager

type BudgetManager interface {
	// GetBudget returns the current vouch budget for a DID
	GetBudget(ctx context.Context, did, context string, epoch int64) (*VouchBudget, error)

	// SpendBudget attempts to spend from a DID's vouch budget
	SpendBudget(ctx context.Context, did, context string, epoch int64, amount float64) error

	// RefillBudget refills a DID's budget based on their current score
	RefillBudget(ctx context.Context, did, context string, epoch int64, score float64) error

	// GetSpentBudget returns total budget spent by a DID in an epoch
	GetSpentBudget(ctx context.Context, did, context string, epoch int64) (float64, error)

	// ValidateBudget ensures budget constraints are met
	ValidateBudget(ctx context.Context, did, context string, epoch int64) error
}

BudgetManager defines the interface for vouch budget management

func NewMemoryBudgetManager

func NewMemoryBudgetManager(config *ScoreConfig, dataProvider DataProvider) BudgetManager

NewMemoryBudgetManager creates a new memory-based budget manager

func NewPersistentBudgetManager

func NewPersistentBudgetManager(config *ScoreConfig, dataProvider DataProvider, storage BudgetStorage) BudgetManager

NewPersistentBudgetManager creates a budget manager with persistent storage

type BudgetStorage

type BudgetStorage interface {
	StoreBudget(ctx context.Context, budget *VouchBudget) error
	GetBudget(ctx context.Context, did, context string, epoch int64) (*VouchBudget, error)
	DeleteBudget(ctx context.Context, did, context string, epoch int64) error
	ListBudgets(ctx context.Context, did, context string, fromEpoch, toEpoch int64) ([]*VouchBudget, error)
}

BudgetStorage defines the interface for budget persistence

type BudgetUtilization

type BudgetUtilization struct {
	DID             string    `json:"did"`
	Context         string    `json:"context"`
	Epoch           int64     `json:"epoch"`
	TotalBudget     float64   `json:"total_budget"`
	SpentBudget     float64   `json:"spent_budget"`
	RemainingBudget float64   `json:"remaining_budget"`
	UtilizationRate float64   `json:"utilization_rate"` // 0.0 to 1.0
	ReputationBond  float64   `json:"reputation_bond"`
	Penalty         float64   `json:"penalty"`
	Timestamp       time.Time `json:"timestamp"`
}

BudgetUtilization provides budget utilization statistics

type CollusionCluster

type CollusionCluster struct {
	Context     string   `json:"context"`
	Epoch       int64    `json:"epoch"`
	Members     []string `json:"members"`      // DIDs in the cluster
	Density     float64  `json:"density"`      // Graph density
	VouchVolume float64  `json:"vouch_volume"` // Total vouch volume
	Confidence  float64  `json:"confidence"`   // Detection confidence
}

CollusionCluster represents a detected collusive group

type ComputeRequest

type ComputeRequest struct {
	DID     string `json:"did"`
	Context string `json:"context"`
	Epoch   int64  `json:"epoch"`

	// Optional parameters
	ForceRecompute bool `json:"force_recompute,omitempty"`
	IncludeProof   bool `json:"include_proof,omitempty"`
	IncludeFactors bool `json:"include_factors,omitempty"`
}

ComputeRequest represents a score computation request

type ComputeResponse

type ComputeResponse struct {
	Score      *Score           `json:"score"`
	Components *ScoreComponents `json:"components,omitempty"`
	Proof      *ScoreProof      `json:"proof,omitempty"`
	CachedFrom *int64           `json:"cached_from,omitempty"` // Epoch if from cache
}

ComputeResponse represents a score computation response

type CustomDecayFunction

type CustomDecayFunction struct {
	DecayType     string  // "exponential", "linear", "power"
	PowerExponent float64 // For power decay: value * (elapsed/halfLife)^(-exponent)
}

CustomDecayFunction allows for configurable decay parameters

func (*CustomDecayFunction) ApplyDecay

func (d *CustomDecayFunction) ApplyDecay(value float64, elapsedEpochs int64, halfLife int64) float64

ApplyDecay implements DecayFunction.ApplyDecay with configurable decay

func (*CustomDecayFunction) ApplyInactivityDecay

func (d *CustomDecayFunction) ApplyInactivityDecay(value float64, inactiveEpochs int64, decayRate float64) float64

ApplyInactivityDecay implements DecayFunction.ApplyInactivityDecay

func (*CustomDecayFunction) ComputeTimeBonus

func (d *CustomDecayFunction) ComputeTimeBonus(firstActivity, lastActivity int64, currentEpoch int64, maxGrowth float64) float64

ComputeTimeBonus implements DecayFunction.ComputeTimeBonus

type DataProvider

type DataProvider interface {
	// GetVouches returns all vouches for a DID up to a given epoch
	GetVouches(ctx context.Context, did, context string, maxEpoch int64) ([]*VouchData, error)

	// GetAttestations returns all attestations for a DID up to a given epoch
	GetAttestations(ctx context.Context, did, context string, maxEpoch int64) ([]*AttestationData, error)

	// GetReports returns all reports against a DID up to a given epoch
	GetReports(ctx context.Context, did, context string, maxEpoch int64) ([]*ReportData, error)

	// GetKYCData returns KYC/PoP data for a DID up to a given epoch
	GetKYCData(ctx context.Context, did, context string, maxEpoch int64) ([]*KYCData, error)

	// GetTimeData returns time-based activity data for a DID
	GetTimeData(ctx context.Context, did, context string, maxEpoch int64) (*TimeData, error)

	// GetScore returns a previously computed score if available
	GetScore(ctx context.Context, did, context string, epoch int64) (*Score, error)

	// StoreScore persists a computed score
	StoreScore(ctx context.Context, score *Score) error
}

DataProvider defines the interface for accessing scoring input data

type DecayFunction

type DecayFunction interface {
	// ApplyDecay applies exponential decay to a value based on time elapsed
	ApplyDecay(value float64, elapsedEpochs int64, halfLife int64) float64

	// ApplyInactivityDecay applies decay for inactivity
	ApplyInactivityDecay(value float64, inactiveEpochs int64, decayRate float64) float64

	// ComputeTimeBonus computes time-based bonus with bounded growth
	ComputeTimeBonus(firstActivity, lastActivity int64, currentEpoch int64, maxGrowth float64) float64
}

DecayFunction defines the interface for decay computations

func NewCustomDecayFunction

func NewCustomDecayFunction(decayType string, powerExponent float64) DecayFunction

NewCustomDecayFunction creates a new custom decay function

func NewExponentialDecayFunction

func NewExponentialDecayFunction() DecayFunction

NewExponentialDecayFunction creates a new exponential decay function

func NewLinearDecayFunction

func NewLinearDecayFunction() DecayFunction

NewLinearDecayFunction creates a new linear decay function

type DenseSubgraph

type DenseSubgraph struct {
	Context   string   `json:"context"`
	Epoch     int64    `json:"epoch"`
	Nodes     []string `json:"nodes"`     // DIDs in subgraph
	Edges     int      `json:"edges"`     // Number of vouch edges
	Density   float64  `json:"density"`   // Subgraph density
	Suspicion float64  `json:"suspicion"` // Suspicion score
}

DenseSubgraph represents a dense subgraph in the vouch network

type DeterministicEngine

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

DeterministicEngine implements the trust scoring algorithm

func NewDeterministicEngine

func NewDeterministicEngine(
	config *ScoreConfig,
	dataProvider DataProvider,
	budgetManager BudgetManager,
	graphAnalyzer GraphAnalyzer,
	decayFunc DecayFunction,
	validator ScoreValidator,
	signer crypto.Signer,
) *DeterministicEngine

NewDeterministicEngine creates a new deterministic scoring engine

func (*DeterministicEngine) ComputeScore

func (e *DeterministicEngine) ComputeScore(ctx context.Context, did, context string, epoch int64) (*Score, error)

ComputeScore implements Engine.ComputeScore

func (*DeterministicEngine) ComputeScores

func (e *DeterministicEngine) ComputeScores(ctx context.Context, dids []string, context string, epoch int64) ([]*Score, error)

ComputeScores implements Engine.ComputeScores

func (*DeterministicEngine) GetFactors

func (e *DeterministicEngine) GetFactors(ctx context.Context, did, context string, epoch int64) (*ScoreComponents, error)

GetFactors implements Engine.GetFactors

func (*DeterministicEngine) GetProof

func (e *DeterministicEngine) GetProof(ctx context.Context, score *Score) (*ScoreProof, error)

GetProof implements Engine.GetProof

func (*DeterministicEngine) RecomputeScore

func (e *DeterministicEngine) RecomputeScore(ctx context.Context, did, context string, epoch int64) (*Score, error)

RecomputeScore implements Engine.RecomputeScore

func (*DeterministicEngine) ValidateScore

func (e *DeterministicEngine) ValidateScore(ctx context.Context, score *Score) error

ValidateScore implements Engine.ValidateScore

func (*DeterministicEngine) VerifyProof

func (e *DeterministicEngine) VerifyProof(ctx context.Context, proof *ScoreProof) error

VerifyProof implements Engine.VerifyProof

type Engine

type Engine interface {
	// ComputeScore computes the trust score for a DID in a given context
	ComputeScore(ctx context.Context, did, context string, epoch int64) (*Score, error)

	// ComputeScores computes scores for multiple DIDs efficiently
	ComputeScores(ctx context.Context, dids []string, context string, epoch int64) ([]*Score, error)

	// RecomputeScore recomputes a score with fresh data
	RecomputeScore(ctx context.Context, did, context string, epoch int64) (*Score, error)

	// GetFactors returns the current factor breakdown for a score
	GetFactors(ctx context.Context, did, context string, epoch int64) (*ScoreComponents, error)

	// ValidateScore validates a computed score against input data
	ValidateScore(ctx context.Context, score *Score) error

	// GetProof generates a cryptographic proof for a score
	GetProof(ctx context.Context, score *Score) (*ScoreProof, error)

	// VerifyProof verifies a cryptographic proof
	VerifyProof(ctx context.Context, proof *ScoreProof) error
}

Engine defines the interface for trust score computation

type ExponentialDecayFunction

type ExponentialDecayFunction struct{}

ExponentialDecayFunction implements DecayFunction with exponential decay

func (*ExponentialDecayFunction) ApplyDecay

func (d *ExponentialDecayFunction) ApplyDecay(value float64, elapsedEpochs int64, halfLife int64) float64

ApplyDecay implements DecayFunction.ApplyDecay Uses exponential decay: value * (0.5)^(elapsedEpochs / halfLife)

func (*ExponentialDecayFunction) ApplyInactivityDecay

func (d *ExponentialDecayFunction) ApplyInactivityDecay(value float64, inactiveEpochs int64, decayRate float64) float64

ApplyInactivityDecay implements DecayFunction.ApplyInactivityDecay Uses exponential decay for inactivity: value * (1 - decayRate)^inactiveEpochs

func (*ExponentialDecayFunction) ComputeTimeBonus

func (d *ExponentialDecayFunction) ComputeTimeBonus(firstActivity, lastActivity int64, currentEpoch int64, maxGrowth float64) float64

ComputeTimeBonus implements DecayFunction.ComputeTimeBonus Computes bounded logarithmic growth: min(maxGrowth, log(1 + age) * activity_factor)

type GraphAnalyzer

type GraphAnalyzer interface {
	// DetectCollusion analyzes the vouch graph for collusive behavior
	DetectCollusion(ctx context.Context, context string, epoch int64) ([]*CollusionCluster, error)

	// ComputeDiversity computes diversity score for a DID's vouch network
	ComputeDiversity(ctx context.Context, did, context string, epoch int64) (float64, error)

	// GetCommunityOverlap returns community overlap metrics for a DID
	GetCommunityOverlap(ctx context.Context, did, context string, epoch int64) (float64, error)

	// GetDenseSubgraphs identifies dense subgraphs that may indicate collusion
	GetDenseSubgraphs(ctx context.Context, context string, epoch int64, threshold float64) ([]*DenseSubgraph, error)
}

GraphAnalyzer defines the interface for graph-based anti-collusion analysis

func NewNetworkGraphAnalyzer

func NewNetworkGraphAnalyzer(dataProvider DataProvider) GraphAnalyzer

NewNetworkGraphAnalyzer creates a new network graph analyzer

type HTTPService

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

HTTPService provides HTTP endpoints for the trust scoring engine

func NewHTTPService

func NewHTTPService(
	engine Engine,
	budgetManager BudgetManager,
	graphAnalyzer GraphAnalyzer,
	config *ScoreConfig,
	port int,
) *HTTPService

NewHTTPService creates a new HTTP service for trust scoring

func (*HTTPService) Start

func (s *HTTPService) Start() error

Start starts the HTTP service

func (*HTTPService) Stop

func (s *HTTPService) Stop(ctx context.Context) error

Stop stops the HTTP service

type KYCData

type KYCData struct {
	DID       string     `json:"did"`
	Context   string     `json:"context"`
	Type      string     `json:"type"`  // kyc, pop, etc.
	Level     int        `json:"level"` // trust level 1-5
	IssuerDID string     `json:"issuer_did"`
	Weight    float64    `json:"weight"`
	Timestamp time.Time  `json:"timestamp"`
	Epoch     int64      `json:"epoch"`
	ExpiresAt *time.Time `json:"expires_at,omitempty"`
}

KYCData represents KYC/PoP credential data for scoring

type LinearDecayFunction

type LinearDecayFunction struct{}

LinearDecayFunction implements DecayFunction with linear decay

func (*LinearDecayFunction) ApplyDecay

func (d *LinearDecayFunction) ApplyDecay(value float64, elapsedEpochs int64, halfLife int64) float64

ApplyDecay implements DecayFunction.ApplyDecay with linear decay Uses linear decay: value * max(0, 1 - (elapsedEpochs / (2 * halfLife)))

func (*LinearDecayFunction) ApplyInactivityDecay

func (d *LinearDecayFunction) ApplyInactivityDecay(value float64, inactiveEpochs int64, decayRate float64) float64

ApplyInactivityDecay implements DecayFunction.ApplyInactivityDecay with linear decay

func (*LinearDecayFunction) ComputeTimeBonus

func (d *LinearDecayFunction) ComputeTimeBonus(firstActivity, lastActivity int64, currentEpoch int64, maxGrowth float64) float64

ComputeTimeBonus implements DecayFunction.ComputeTimeBonus with square root growth

type MemoryBudgetManager

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

MemoryBudgetManager implements BudgetManager using in-memory storage In production, this would be backed by persistent storage

func (*MemoryBudgetManager) GetBudget

func (m *MemoryBudgetManager) GetBudget(ctx context.Context, did, context string, epoch int64) (*VouchBudget, error)

GetBudget implements BudgetManager.GetBudget

func (*MemoryBudgetManager) GetSpentBudget

func (m *MemoryBudgetManager) GetSpentBudget(ctx context.Context, did, context string, epoch int64) (float64, error)

GetSpentBudget implements BudgetManager.GetSpentBudget

func (*MemoryBudgetManager) RefillBudget

func (m *MemoryBudgetManager) RefillBudget(ctx context.Context, did, context string, epoch int64, score float64) error

RefillBudget implements BudgetManager.RefillBudget

func (*MemoryBudgetManager) SpendBudget

func (m *MemoryBudgetManager) SpendBudget(ctx context.Context, did, context string, epoch int64, amount float64) error

SpendBudget implements BudgetManager.SpendBudget

func (*MemoryBudgetManager) ValidateBudget

func (m *MemoryBudgetManager) ValidateBudget(ctx context.Context, did, context string, epoch int64) error

ValidateBudget implements BudgetManager.ValidateBudget

type NetworkGraphAnalyzer

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

NetworkGraphAnalyzer implements GraphAnalyzer using network analysis algorithms

func (*NetworkGraphAnalyzer) ComputeDiversity

func (g *NetworkGraphAnalyzer) ComputeDiversity(ctx context.Context, did, context string, epoch int64) (float64, error)

ComputeDiversity implements GraphAnalyzer.ComputeDiversity

func (*NetworkGraphAnalyzer) DetectCollusion

func (g *NetworkGraphAnalyzer) DetectCollusion(ctx context.Context, context string, epoch int64) ([]*CollusionCluster, error)

DetectCollusion implements GraphAnalyzer.DetectCollusion

func (*NetworkGraphAnalyzer) GetCommunityOverlap

func (g *NetworkGraphAnalyzer) GetCommunityOverlap(ctx context.Context, did, context string, epoch int64) (float64, error)

GetCommunityOverlap implements GraphAnalyzer.GetCommunityOverlap

func (*NetworkGraphAnalyzer) GetDenseSubgraphs

func (g *NetworkGraphAnalyzer) GetDenseSubgraphs(ctx context.Context, context string, epoch int64, threshold float64) ([]*DenseSubgraph, error)

GetDenseSubgraphs implements GraphAnalyzer.GetDenseSubgraphs

type PersistentBudgetManager

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

PersistentBudgetManager implements BudgetManager with persistent storage

func (*PersistentBudgetManager) GetBudget

func (p *PersistentBudgetManager) GetBudget(ctx context.Context, did, context string, epoch int64) (*VouchBudget, error)

GetBudget implements BudgetManager.GetBudget with persistence

func (*PersistentBudgetManager) GetSpentBudget

func (p *PersistentBudgetManager) GetSpentBudget(ctx context.Context, did, context string, epoch int64) (float64, error)

GetSpentBudget implements BudgetManager.GetSpentBudget

func (*PersistentBudgetManager) RefillBudget

func (p *PersistentBudgetManager) RefillBudget(ctx context.Context, did, context string, epoch int64, score float64) error

RefillBudget implements BudgetManager.RefillBudget with persistence

func (*PersistentBudgetManager) SpendBudget

func (p *PersistentBudgetManager) SpendBudget(ctx context.Context, did, context string, epoch int64, amount float64) error

SpendBudget implements BudgetManager.SpendBudget with persistence

func (*PersistentBudgetManager) ValidateBudget

func (p *PersistentBudgetManager) ValidateBudget(ctx context.Context, did, context string, epoch int64) error

ValidateBudget implements BudgetManager.ValidateBudget

type ReportData

type ReportData struct {
	ReporterDID string    `json:"reporter_did"`
	ReportedDID string    `json:"reported_did"`
	Context     string    `json:"context"`
	Severity    float64   `json:"severity"` // 0.0 to 1.0
	Adjudicated bool      `json:"adjudicated"`
	Upheld      bool      `json:"upheld"`
	Timestamp   time.Time `json:"timestamp"`
	Epoch       int64     `json:"epoch"`
}

ReportData represents a report against an identity for scoring

type Score

type Score struct {
	DID       string    `json:"did"`
	Context   string    `json:"context"`
	Value     float64   `json:"value"`
	Epoch     int64     `json:"epoch"`
	Timestamp time.Time `json:"timestamp"`

	// Component breakdown
	Components ScoreComponents `json:"components"`

	// Metadata
	ComputedBy string `json:"computed_by"`
	Version    string `json:"version"`
}

Score represents a computed trust score for an identity

type ScoreComponents

type ScoreComponents struct {
	K float64 `json:"k"` // PoP/KYC factor
	A float64 `json:"a"` // Attestations factor
	V float64 `json:"v"` // Vouches factor (with sqrt aggregation)
	R float64 `json:"r"` // Reports factor (negative)
	T float64 `json:"t"` // Time factor
}

ScoreComponents breaks down the score into its constituent factors

type ScoreConfig

type ScoreConfig struct {
	// Factor weights
	Factors ScoreFactors `json:"factors"`

	// Vouch configuration
	VouchCap       float64 `json:"vouch_cap"`        // Maximum vouch weight cap
	VouchDecayRate float64 `json:"vouch_decay_rate"` // Exponential decay rate
	VouchHalfLife  int64   `json:"vouch_half_life"`  // Half-life in epochs

	// Report configuration
	ReportDecayRate float64 `json:"report_decay_rate"` // Report decay rate
	ReportHalfLife  int64   `json:"report_half_life"`  // Report half-life in epochs

	// Time configuration
	TimeMaxGrowth       float64 `json:"time_max_growth"`       // Maximum time factor growth
	TimeInactivityDecay float64 `json:"time_inactivity_decay"` // Decay rate for inactivity

	// Budget configuration
	BaseBudget       float64 `json:"base_budget"`       // Base vouch budget per epoch
	BudgetMultiplier float64 `json:"budget_multiplier"` // Score-based budget multiplier

	// Diversity configuration
	DiversityPenalty   float64 `json:"diversity_penalty"`   // Penalty for low diversity
	CommunityThreshold float64 `json:"community_threshold"` // Threshold for community detection

	// Anti-collusion
	CollusionThreshold float64 `json:"collusion_threshold"` // Dense subgraph threshold
	CollusionPenalty   float64 `json:"collusion_penalty"`   // Penalty for collusion
}

ScoreConfig holds configuration for score computation

func DefaultScoreConfig

func DefaultScoreConfig() *ScoreConfig

DefaultScoreConfig returns default configuration

type ScoreFactors

type ScoreFactors struct {
	Alpha float64 `json:"alpha"` // Weight for K factor
	Beta  float64 `json:"beta"`  // Weight for A factor
	Gamma float64 `json:"gamma"` // Weight for V factor
	Delta float64 `json:"delta"` // Weight for R factor (subtracted)
	Tau   float64 `json:"tau"`   // Weight for T factor
}

ScoreFactors defines the weights for each component in the scoring algorithm

func DefaultScoreFactors

func DefaultScoreFactors() ScoreFactors

DefaultScoreFactors returns the default factor weights

type ScoreProof

type ScoreProof struct {
	Score     *Score    `json:"score"`
	InputHash string    `json:"input_hash"` // Hash of all input data
	Signature []byte    `json:"signature"`  // Signature over score and input hash
	PublicKey []byte    `json:"public_key"` // Public key for verification
	Algorithm string    `json:"algorithm"`  // Signing algorithm
	Timestamp time.Time `json:"timestamp"`  // Proof timestamp
}

ScoreProof provides cryptographic proof of score computation

type ScoreValidator

type ScoreValidator interface {
	// ValidateInputData validates all input data for score computation
	ValidateInputData(ctx context.Context, did, context string, epoch int64) error

	// ValidateScoreRange ensures score is within expected bounds
	ValidateScoreRange(score float64) error

	// ValidateComponents ensures component values are consistent
	ValidateComponents(components *ScoreComponents, factors *ScoreFactors) error

	// ValidateIntegrity performs integrity checks on score data
	ValidateIntegrity(ctx context.Context, score *Score) error
}

ScoreValidator defines the interface for score validation

type TimeData

type TimeData struct {
	DID           string    `json:"did"`
	Context       string    `json:"context"`
	FirstActivity time.Time `json:"first_activity"`
	LastActivity  time.Time `json:"last_activity"`
	ActivityCount int64     `json:"activity_count"`
	Epoch         int64     `json:"epoch"`
}

TimeData represents time-based scoring factors

type VouchBudget

type VouchBudget struct {
	DID             string  `json:"did"`
	Context         string  `json:"context"`
	Epoch           int64   `json:"epoch"`
	TotalBudget     float64 `json:"total_budget"`
	SpentBudget     float64 `json:"spent_budget"`
	RemainingBudget float64 `json:"remaining_budget"`
	ReputationBond  float64 `json:"reputation_bond"`
}

VouchBudget represents spending limits for vouching

type VouchData

type VouchData struct {
	FromDID   string    `json:"from_did"`
	ToDID     string    `json:"to_did"`
	Context   string    `json:"context"`
	Strength  float64   `json:"strength"` // q_ij in the formula
	Timestamp time.Time `json:"timestamp"`
	Epoch     int64     `json:"epoch"`
}

VouchData represents a vouch relationship for scoring

type VouchEdge

type VouchEdge struct {
	From     string
	To       string
	Weight   float64
	Strength float64
	Epoch    int64
}

VouchEdge represents an edge in the vouch graph

type VouchGraph

type VouchGraph struct {
	Nodes   map[string]bool        // Set of all nodes (DIDs)
	Edges   []VouchEdge            // All vouch edges
	AdjList map[string][]VouchEdge // Adjacency list representation
}

VouchGraph represents the vouch graph for analysis

Jump to

Keyboard shortcuts

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