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
  1. Integration

Private Messaging

In DPSN, private messaging involves a two-step process:

  1. Key Exchange: The publisher initially sends an encrypted key to the subscriber.

  2. Message Encryption: Subsequent messages are encrypted using this shared key.

Integrating with the DPSN SDK

Publisher Side

  1. Create a Private Message Channel: Use the createPrivateChannel function to generate a unique channel key.

  2. Publish the Public Key: Publish the public key to a designated topic.

  3. Encrypt and Send Messages: Use the publishPrivateMessage function to encrypt and send messages to the specified channel.

JavaScript

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

// Create a publisher instance and publish keys
const publisherPrivateChannel = new DPSN.Publisher(process.env.DPSN_DELEGATED_ADDRESS_PVTKEY, 'your_topic');
// Publish key
await publisherPrivateChannel.createPrivateChannel();
// Publish a message
publisherPrivateChannel.publishPrivateMessage(message);

Subscriber Side

  1. Subscribe to the Topic: Subscribe to the topic where the public key was published.

  2. Receive and Store Public Key: The SDK will automatically handle receiving and storing the public key.

  3. Decrypt Messages: Use the decryptPrivateMessage function to decrypt incoming messages on the topic.

JavaScript

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

// Create a subscriber instance
const subscriber = new DPSN.Subscriber(process.env.DPSN_DELEGATED_ADDRESS_PVTKEY, 'your_topic');

// Subscribe to the topic
subscriber.subscribeToTopic('your_topic', (message) => {
  // Decrypt the message. The first key message will return null
  const decryptedMessage = subscriber.decryptPrivateMessage(message);
  if(decryptedMessage) process(decryptedMessage);
});

Key Features and Benefits

  • Simplified Integration: The SDK handles key generation, encryption, and decryption, making it easy to implement private messaging.

  • Security: DPSN ensures the security of private messages through robust encryption and key management.

  • Scalability: The system can handle a large number of private messages and subscribers.

  • Flexibility: Publishers can create multiple private channels and control access to them.

PreviousDelegated AddressesNextMessaging Application

Last updated 8 months ago