OpenMSCP
  • Welcome
    • Introduction
    • OpenMSCP
  • Tokenomics
  • OpenMSCP SDK
    • About
    • Prerequisities & Installation
    • Quick Start
    • SDK Core
      • Profiles
      • Posts
      • Messaging
    • Contributing
  • MSCP Social
    • What is MSCP Social?
    • Registration
    • Features
Powered by GitBook
On this page
  • Message Encryption
  • Sending Messages
  • Message Threads
  • Message Security
  • Message Queries
  • Message Events
  • Message Management
  • Message Media
  1. OpenMSCP SDK
  2. SDK Core

Messaging

Message Encryption

The SDK implements end-to-end encryption for secure messaging.

Encryption Setup

// Initialize encryption
await client.message.initializeEncryption();

// Generate encryption keys
const keys = await client.message.generateKeys();

// Exchange public keys
await client.message.exchangeKeys(recipientPublicKey, publicKey);

Encryption Types

enum EncryptionType {
  SYMMETRIC = 'symmetric',
  ASYMMETRIC = 'asymmetric',
  HYBRID = 'hybrid'
}

interface EncryptionConfig {
  type: EncryptionType;
  algorithm: string;
  keySize: number;
  padding: string;
}

Sending Messages

Basic Message Sending

// Send a text message
const message = await client.message.send(recipientPublicKey, {
  content: 'Hello!',
  type: 'text'
});

// Send a message with media
const mediaMessage = await client.message.send(recipientPublicKey, {
  content: 'Check this out!',
  type: 'media',
  media: [{
    type: 'image',
    url: 'ipfs://QmHash...'
  }]
});

Message Types

interface Message {
  publicKey: PublicKey;
  sender: PublicKey;
  recipient: PublicKey;
  content: string;
  type: MessageType;
  encrypted: boolean;
  createdAt: number;
  status: MessageStatus;
  metadata?: Record<string, any>;
}

enum MessageType {
  TEXT = 'text',
  MEDIA = 'media',
  FILE = 'file',
  LOCATION = 'location',
  CONTACT = 'contact'
}

enum MessageStatus {
  SENT = 'sent',
  DELIVERED = 'delivered',
  READ = 'read',
  FAILED = 'failed'
}

Message Threads

Thread Management

// Create a new thread
const thread = await client.message.createThread(recipientPublicKey);

// Get thread messages
const messages = await client.message.getThread(threadPublicKey);

// Get all threads
const threads = await client.message.getAllThreads();

// Delete a thread
await client.message.deleteThread(threadPublicKey);

Thread Interface

interface Thread {
  publicKey: PublicKey;
  participants: PublicKey[];
  lastMessage: Message;
  unreadCount: number;
  createdAt: number;
  updatedAt: number;
  metadata?: Record<string, any>;
}

Message Security

Security Features

// Enable message encryption
await client.message.enableEncryption();

// Set encryption preferences
await client.message.setEncryptionPreferences({
  type: EncryptionType.HYBRID,
  requireEncryption: true,
  autoDelete: true,
  deleteAfter: 7 * 24 * 60 * 60 * 1000 // 7 days
});

// Verify message integrity
const isValid = await client.message.verifyMessage(messagePublicKey);

Security Configuration

interface SecurityConfig {
  encryption: {
    type: EncryptionType;
    requireEncryption: boolean;
    keyRotation: number;
  };
  privacy: {
    readReceipts: boolean;
    typingIndicators: boolean;
    onlineStatus: boolean;
  };
  retention: {
    autoDelete: boolean;
    deleteAfter: number;
  };
}

Message Queries

Basic Queries

// Get a single message
const message = await client.message.get(messagePublicKey);

// Get messages by thread
const threadMessages = await client.message.getByThread(threadPublicKey);

// Get unread messages
const unread = await client.message.getUnread();

Advanced Queries

// Search messages
const searchResults = await client.message.search({
  query: 'important',
  filters: {
    dateRange: {
      start: new Date('2023-01-01'),
      end: new Date()
    },
    type: MessageType.TEXT
  }
});

// Get message statistics
const stats = await client.message.getStats();

// Get message metadata
const metadata = await client.message.getMetadata(messagePublicKey);

Message Events

The SDK provides event listeners for message-related activities.

// Listen for new messages
client.message.onNew((message) => {
  console.log('New message:', message);
});

// Listen for message status changes
client.message.onStatusChange((status) => {
  console.log('Message status changed:', status);
});

// Listen for typing indicators
client.message.onTyping((typing) => {
  console.log('User is typing:', typing);
});

Message Management

Message Actions

// Mark message as read
await client.message.markAsRead(messagePublicKey);

// Delete a message
await client.message.delete(messagePublicKey);

// Forward a message
await client.message.forward(messagePublicKey, newRecipientPublicKey);

// Reply to a message
await client.message.reply(messagePublicKey, 'Reply content');

Message Moderation

// Report a message
await client.message.report(messagePublicKey, {
  reason: 'spam',
  details: 'This message contains spam content'
});

// Block a sender
await client.message.blockSender(senderPublicKey);

// Mute a thread
await client.message.muteThread(threadPublicKey);

Message Media

Media Handling

// Upload message media
const media = await client.message.uploadMedia(file, {
  type: 'image',
  maxSize: 10 * 1024 * 1024 // 10MB
});

// Send media message
const message = await client.message.send(recipientPublicKey, {
  type: 'media',
  media: [media]
});

// Download message media
const file = await client.message.downloadMedia(mediaPublicKey);
PreviousPostsNextContributing

Last updated 1 month ago