2.0.2 • Published 5 months ago

@hsuite/trust-score v2.0.2

Weekly downloads
-
License
-
Repository
github
Last release
5 months ago

@hsuite/trust-score

A powerful and extensible trust score calculation system that helps evaluate user trustworthiness across multiple social platforms.

Overview

The trust-score library provides a modular system for calculating user trust scores based on their social media presence and activity. It currently supports Twitter and Discord platforms, with a plugin-based architecture that allows for easy extension to additional platforms.

Features

  • Pluggable architecture for multiple trust score providers
  • Weighted score calculation system
  • Built-in support for:
    • Twitter verification and scoring
    • Discord activity tracking and reputation system
  • Account verification workflows
  • Real-time activity monitoring (Discord)
  • REST API endpoints for verification and activation

Installation

npm install @hsuite/trust-score

Dependencies

  • Node.js >= 14
  • NestJS >= 10.4.2
  • twitter-api-v2 ^1.15.1
  • discord.js ^14.11.0

Module Setup

import { TrustScoreModule } from '@hsuite/trust-score';

@Module({
  imports: [
    TrustScoreModule
  ]
})
export class AppModule {}

Environment Variables

The following environment variables are required:

Twitter Plugin

  • TWITTER_API_KEY - Twitter API key for authentication
  • TWITTER_TARGET_ACCOUNT - Target Twitter account for relevance scoring

Discord Plugin

  • DISCORD_BOT_TOKEN - Discord bot token for authentication
  • DISCORD_TARGET_GUILD - Target Discord guild ID
  • DISCORD_TARGET_ROLE - Role ID for trust verification
  • DISCORD_REPUTATION_CHANNEL - Channel ID for reputation tracking

Trust Score Calculation

Twitter Score Components (50% weight)

  • Follower count (max 30 points)
  • Account age (max 20 points)
  • Relevant tweets mentioning target account (max 50 points)

Discord Score Components (50% weight)

  • Account age in server (max 15 points)
  • Role status (15 points)
  • Activity score (max 40 points)
    • Message count (1 point per 50 messages)
    • Reactions received (1 point per 20 reactions)
    • Mentions received (2 points per mention)
  • Reputation votes (max 30 points)
    • Each upvote: +3 points
    • Each downvote: -3 points

API Endpoints

Verify Account

POST /trust-score/verify/:provider
Authorization: Bearer JWT
Body: { id: string }

Activate Account

POST /trust-score/activate/:provider
Authorization: Bearer JWT
Body: { id: string, code: string }

Plugin Interface

Implement the ITrustScorePlugin interface to create new trust score providers:

interface ITrustScorePlugin {
  readonly name: string;
  readonly weight: number;
  
  calculateScore(userId: string): Promise<ITrustScore>;
  verifyAccount(userId: string, data: any): Promise<boolean>;
  activateAccount(userId: string, data: any): Promise<void>;
}

Trust Score Interface

interface ITrustScore {
  score: number;          // Score between 0-100
  timestamp: Date;        // When the score was calculated
  provider: string;       // Which plugin provided this score
  details: any;          // Provider-specific details
  userId: string;        // User ID this score belongs to
}

Documentation

Generate detailed documentation using:

npm run compodoc

View documentation coverage:

npm run compodoc:coverage
2.0.2

5 months ago

2.0.1

5 months ago