DPSN: Decentralised Pub/Sub Network
  • Introduction
  • Why Decentralized?
  • Understanding Topics
  • Architecture
    • Topics Registry
    • Configurator
    • Clusters
    • Publishers and Subscribers
    • Facilitator Brokers
    • SDK
  • Functionality
    • Message Publishing and Delivery
    • Subscription Management
    • Security Considerations
    • Topic Ownership and Access Control
    • Private Key Authentication
    • Fully Homomorphic Encryption Support
  • Advantages and Use Cases
    • Advantages of DPSN
    • Use Cases
  • Integration
    • SDK Introduction
    • Publisher
    • Subscriber
    • Delegated Addresses
    • Private Messaging
  • Integration Guides
    • Messaging Application
  • Token Use
    • Utility
    • Token Utility Model
  • DIPs
    • DIP1: Stateless Message Routing in DPSN
  • DIP2: Integration of DPSN with Model Context Protocol (MCP)
  • DIP-3: Standardizing DPSN AVS for Enhanced Security and Reliability
Powered by GitBook
On this page
  • Understanding the Architecture
  • Integration Steps
  1. Integration Guides

Messaging Application

Understanding the Architecture

  • Decentralized Network: DPSN operates as a decentralized network, with nodes distributed across various locations.

  • Topics: Messages are organized into topics to facilitate routing and subscription.

  • User Accounts: Users have accounts on the DPSN network, associated with public and private key pairs.

  • Socket or MQTT Connections: Users connect to the DPSN network using WebSocket or MQTT connections.

Integration Steps

Publisher Side

  1. Generate a Salt: Create a random salt value.

  2. Encrypt Salt: Encrypt the salt using the recipient's public key.

  3. Publish Salt: Publish the encrypted salt to the designated topic.

  4. Encrypt Messages: Encrypt messages using the salt and the recipient's public key.

  5. Publish Encrypted Messages: Publish encrypted messages to the topic.

const DPSN = require('dpsn-sdk');

// ... (other initialization steps)

// Generate a salt
const salt = generateSalt();

// Encrypt the salt
const encryptedSalt = encryptMessage(salt, recipientPublicKey);

// Publish the encrypted salt
dpsn.publishMessage('project_chat.userB', encryptedSalt);

// ... (publish encrypted messages using the salt)

Send the updated messages with encrypted salt version to the subscriber so that subscriber can decide to skip decryption again to save time or decrypt if the salt was not received.

// Encrypt the message
const encryptedMessage = encryptMessage(message, recipientPublicKey, salt);

// Publish the message and salt
dpsn.publishMessage('project_chat.userB', {
  message: encryptedMessage,
  salt: salt
});

Subscriber Side

  1. Subscribe to Topic: Subscribe to the relevant topic.

  2. Receive and Decrypt Salt: When the initial salt message is received, decrypt it using the private key.

  3. Decrypt Messages: Use the salt and the recipient's private key to decrypt subsequent messages.

const DPSN = require('dpsn-sdk');

// ... (other initialization steps)

dpsn.subscribeToTopic('project_chat.userB', (message) => {
  if (isSaltMessage(message)) {
    // Decrypt and update the salt
    encryptedSalt = message;
    salt = decryptMessage(message, privateKey);
    // Store the salt for future use
  } else {
    // Decrypt the message using the salt
    // optionally check salt with encryptedSalt first to ensure you have the updated salt
    const decryptedMessage = decryptMessage(message.message, salt);
    console.log('Decrypted message:', decryptedMessage);
  }
});

PreviousPrivate MessagingNextUtility

Last updated 8 months ago