# Introduction

#### Quick Summary for experts:&#x20;

\
`A real-time decentralized data distribution network.`

**`Key Features`**

* **`Decentralized Nodes`**`: Data distribution powered by independent nodes.`
* **`Topic-Based Messaging`**`: Publish-subscribe model for data streams that can be sent only by allowed addresses.`
* **`Secure and Transparent`**`: Verifiable ownership, cryptographic security, and traceability.`
* **`Custom Monetization`**`: Publishers earn gas fees, fostering an open economy.`
* **`Ecosystem Platform Apps`**` ``that unlocks use cases in realtime communication not possible before this for creating trustless infrastructure.`&#x20;

## Introduction

The digital age has been a relentless march towards decentralization. It began with [**Bitcoin**](https://bitcoin.org/), a revolutionary concept that introduced a **decentralized currency**, unshackling finance from traditional intermediaries. [**Ethereum**](https://ethereum.org/) followed, introducing **smart contracts**, automating agreements and creating the foundation for decentralized applications (dApps). The landscape shifted once again with [**IPFS**](https://ipfs.tech/), a decentralized **file storage** system that challenged the centralized cloud storage paradigm.

While these breakthroughs transformed various sectors, a critical void persisted: [**decentralized messaging**](https://dpsn.org). For over eight years, as pioneers in high-frequency messaging blockchain applications, we've grappled with the limitations of centralized systems. Their centralized control points, single points of failure, and susceptibility to censorship have hindered our ability to build truly resilient and trustworthy applications.

Decentralization is paramount for messaging systems. It ensures data integrity, prevents censorship, and fosters a level playing field for all participants. A decentralized messaging network eliminates the risk of a single entity controlling the flow of information, thereby safeguarding against manipulation and surveillance. It is in this context that we introduce DPSN, a [**Decentralised Publish-Subscribe Network**](https://dpsn.org) designed to address the shortcomings of centralized messaging systems and usher in a new era of decentralized communication.

### What is DPSN

DPSN is a **decentralized publish-subscribe network** designed to provide a high-performance, resilient, and censorship-resistant platform for real-time data distribution. It employs a distributed architecture comprising multiple interconnected clusters, each consisting of a set of geographically proximate nodes.

A distinctive feature of DPSN is its integration of **Fully Homomorphic Encryption (FHE)**. This advanced cryptographic technique allows data to be processed in encrypted form, preserving data privacy while enabling meaningful computations. By safeguarding sensitive information at every stage, from creation to consumption, DPSN sets a new standard for secure data sharing.

DPSN's versatility shines in diverse applications.

* In **DeFi**, it can power high-speed oracles, enabling real-time price feeds and decentralized exchanges to enable high frequency trading.
* For **IoT**, it efficiently handles vast data streams from sensors, optimizing smart city infrastructure and industrial automation.
* In **social messaging**, it offers secure, censorship-resistant platforms, fostering open communication and decentralized social networks.
* Moreover, DPSN is pivotal for **DePIN**, facilitating peer-to-peer resource sharing, energy trading, and decentralized supply chain management.

Its high throughput and low latency make it a cornerstone for building a new generation of decentralized applications across various industries.

#### Core Components and Functionalities

* **Topics Registry:** A distributed ledger maintained by a consensus mechanism records topic creation, ownership, and transfer. Topics are hashed to ensure uniqueness and security.
* **Configurators:** Intelligent agents responsible for mapping topics to clusters based on load balancing, network latency, and security considerations. They utilize a distributed algorithm to achieve consensus on topic-to-cluster assignments.
* **Clusters:** Independent, fault-tolerant networks of nodes that process and disseminate messages. Each cluster employs a robust consensus mechanism to ensure data consistency and availability.
* **Publishers:** Entities that create and own topics. They publish messages to their topics using a secure, authenticated protocol.
* **Subscribers:** Entities that subscribe to topics of interest. They receive messages from multiple clusters to enhance reliability and fault tolerance.
* **Facilitator Brokers:** Intermediate nodes that provides additional services like message filtering, aggregation, and transformation.

<figure><img src="/files/FfqOYj28fnYZGouM97fq" alt=""><figcaption><p>DPSN Architecture</p></figcaption></figure>

#### Consensus and Fault Tolerance

DPSN leverages a hybrid consensus approach, combining a global consensus mechanism for the Topics Registry with independent consensus mechanisms within each cluster. This architecture ensures data consistency, fault tolerance, and scalability.

* **Topics Registry:** Proof-of-Stake or a similar consensus algorithm is used to maintain the integrity of topic ownership and metadata.
* **Clusters:** Each cluster employs a consensus protocol to ensure data consistency and availability within the cluster. This enables fault tolerance and recovery from node failures.

#### Message Routing and Delivery

* **Topic-based Routing:** Messages are routed to specific clusters based on the topic-to-cluster mapping maintained by Configurators.
* **Message Replication:** Each message is replicated across multiple nodes within the target clusters to enhance availability and fault tolerance.
* **Message Delivery:** Subscribers receive messages from multiple clusters and employ a consensus or majority voting mechanism to determine decision making action.

#### Security and Privacy

* **Cryptography:** End-to-end encryption is employed to protect message confidentiality.
* **Authentication:** Publishers and subscribers are authenticated using cryptographic keys to prevent unauthorized access.
* **Access Control:** Topic ownership and permissions are strictly enforced to prevent unauthorized publishing and subscription.
* **Privacy:** DPSN adheres to privacy-enhancing technologies to protect user data.

#### Performance and Scalability

* **Horizontal Scaling:** DPSN can scale horizontally by adding new clusters to accommodate increasing message volume and subscriber numbers.
* **Sharding:** Topics can be partitioned across multiple clusters to improve performance and reduce load on individual clusters.
* **Optimized Protocols:** Efficient messaging protocols and data structures are employed to minimize latency and maximize throughput.

DPSN provides a robust foundation for building a wide range of decentralized applications that rely on real-time data distribution.


# Why Decentralized?

DPSN (Decentralized Publish-Subscribe Network) brings the **trustless transparency** of decentralized systems to real-time data distribution. Here's why decentralization is critical to DPSN's vision and how it transforms messaging, data integrity, and ecosystem innovation:

1. #### Trust, Trust, Trust

Decentralized systems inherently foster trust because they operate transparently. Participants can clearly see how data is handled, who accesses it, and what mechanisms are in place to ensure security and performance. Messaging as a core layer must be trustless, where every participant can verify operations without relying on central authorities.

2. #### An Ever-Persisting System

A decentralized system eliminates single points of failure, ensuring it always operates, even if some nodes go offline or are attacked. DPSN is architected in a way that malicious nodes can not spam the integrity of the data.\
\
Example:

* Centralized Risk: In 2021, Facebook’s centralized servers experienced an outage that took down their entire ecosystem, impacting billions of users globally.
* Decentralized Advantage: With DPSN, node failures don’t disrupt the entire network. If an OracleStream node fails, other nodes pick up the slack, ensuring uninterrupted data flow for critical applications like DeFi trading or IoT monitoring.

3. #### Operator Integrity Without Manipulation

Decentralized operators are governed by transparent protocols, ensuring no hidden fees, unauthorized data manipulation, or monopolistic practices.\
\
Example:

* Centralized Risk: Traditional financial data providers often inflate costs, creating barriers for smaller developers while centralizing data control. Centralized parties can favour one entity vs another by providing them faster access to data for premium, liabilities or closeness.&#x20;
* Decentralized Advantage: In DPSN, gas fees are fixed and transparent. For instance, a developer subscribing to a price feed in OracleStream knows exactly how much they’re paying in TLOS, with no hidden fees. Transparency is enforced by the open network, and bad actors can’t manipulate the system.

4. #### Data Security Through Openness

Decentralization demands, and is impossible to operate without robust encryption and privacy mechanisms to ensure data security, as all operations occur in an open system visible to everyone.

\
Example:

* Centralized Risk: Centralized systems can expose sensitive data through hacks or insider breaches, like the Equifax breach that leaked personal financial information of 147 million people. Would you ever share your private information over centralized infrastructures trusting none of their internal parties or engineers can never find information in their logs? There has to be proof of encryption etc. When is the last time you started checking encryption of every app you have used. Apps built over DPSN have trust built into the foundational thesis.&#x20;
* Decentralized Advantage: DPSN employs advanced encryption protocols for data transmission. For example, a decentralized IoT feed publishing live weather data on DPSN uses end-to-end encryption to prevent eavesdropping, even though the network operates transparently.

5. #### Open Ecosystem Innovation

Decentralization creates an open ecosystem where anyone can contribute, innovate, or access the system, fostering competition and growth.\
\
Example:

* Centralized Risk: Closed ecosystems like traditional oracles (e.g., Bloomberg) limit data to privileged entities, stifling innovation.
* Decentralized Advantage: In DPSN, anyone can publish or subscribe to real-time feeds. DPSN OracleStreams are building a validation system that can further verify the data like Oracles do.\
  For instance, a small startup can create custom oracles for niche use cases (like tracking ESG metrics) without relying on gatekeepers, making the system accessible and driving innovation.


# Understanding Topics

**Topics are backbone of any messaging pub/sub infrastructure that enables routing of messages from publishers to subscribers and any pub/sub messaging infrastructure main goal is to make them happen efficiently with thre required traits of the infrastructure.**

Our core focus is to provide a decentralised Pub/Sub infrastructure to the world that is as fast and reliable as any other messaging infrastructure that exists today like AWS's SQS / SNS / Kinesis etc., Google's Firebase Cloud Messaging / GCM, Azure Service Bus along with added advantages of decentralised infrastructure like privacy, security and censorship resistance.

**Topics in DPSN are essentially named channels or feeds of messages.** Similar to other pub/sub systems, they serve as a way to categorize and distribute data to interested subscribers.

#### Key Characteristics of Topics in DPSN

* **Decentralized Ownership:** Unlike traditional pub/sub systems, topics in DPSN have owners who control access and publishing rights.
* **Transferable:** Topic ownership can be transferred between users, enabling a dynamic marketplace for topics.
* **Hierarchical Structure:** Topics can be organized in a hierarchical structure, allowing for granular categorization.
* **FHE Compatibility:** DPSN supports fully homomorphic encryption, enabling privacy-preserving data sharing through topics.

#### Example: A Financial Data Platform ( following topics and subtopics are just example and not real topics of data streams)&#x20;

A financial data platform might use DPSN topics in the following way:

* **Primary Topic:** "ogtest-73803f8d5e"
* **Sub-topics:**
  * ogtest-73803f8d5e/cryptocurrency &#x20;
  * ogtest-73803f8d5e/stocks&#x20;
  * ogtest-73803f8d5e/forex

Within these sub-topics, more specific topics can be created:

* ogtest-73803f8d5e/cryptocurrency/bitcoin/pric&#x65;**:** Real-time Bitcoin price data
* ogtest-73803f8d5e/cryptocurrency/bitcoin/volum&#x65;**:** Real-time Bitcoin volume data
* ogtest-73803f8d5e/cryptocurrency/ethereum/pric&#x65;**:** Real-time Ethereum price data
* ogtest-73803f8d5e/stocks/nasdaq/AAPL/pric&#x65;**:** Apple stock price data from Nasdaq

**Subscribers** can then subscribe to these topics to receive the specific data they are interested in. For instance, a trader system might subscribe to the "ogtest-73803f8d5e/cryptocurrency/bitcoin/price" topic to get real-time Bitcoin price updates. A trader system who is interested in volumes of all currencies can subscribe to wildcard topic "ogtest-73803f8d5e/cryptocurrency/bitcoin/volume"*. Similarly, a trader system interested in all stocks data can subscribe to* ogtest-73803f8d5e/stock&#x73;*.*

Topics in DPSN are a fundamental building block for organizing and distributing data. Their decentralized nature, combined with the support for FHE, makes DPSN a powerful platform for secure and efficient data sharing.


# Topics Registry

The Topics Registry serves as the foundational layer for managing and governing topics within the network. This distributed ledger is responsible for recording the creation, ownership, and transfer of topics.

#### Core Functionalities

* **Topic Creation:** Any entity DPSN tokens can create a new topic with DPSN tokens. Upon creation, the topic's details, including owner, creation time, and associated metadata, are recorded on the registry.
* **Topic Ownership:** The Topics Registry maintains a clear record of topic ownership. Ownership can be transferred between entities through on-chain transactions.
* **Topic Metadata:** Additional information about a topic, such as description, access controls, and expiration date, can be stored within the registry.
* **Topic Resolution:** The registry provides a mechanism for resolving topic names to their corresponding identifiers, enabling efficient routing of messages.

#### Technical Implementation

The Topics Registry is implemented as a distributed ledger, ensuring transparency, immutability, and auditability. It employs a consensus mechanism to achieve agreement among network participants on the registry's state.

To enhance performance and scalability, the registry can be partitioned into multiple shards, each managing a subset of topics. This approach enables parallel processing of topic-related operations and reduces the load on individual nodes.

### Topics Management

Effective management of topics is essential for the smooth operation of the DPSN network. This subsection outlines the key aspects of topic management.

#### Core Functionalities

* **Topic Creation:** The process of creating new topics, including specifying topic name, description, and associated metadata.
* **Topic Modification:** The ability to update topic attributes, such as description or access controls.
* **Topic Deletion:** The process of removing a topic from the network, considering potential impacts on subscribers and published messages.
* **Topic Lifecycle Management:** Oversight of the entire lifecycle of a topic, from creation to deletion.

#### Technical Implementation

Topic management is implemented through interactions with the Topics Registry. Publishers and authorized administrators can perform topic management operations using the provided APIs or SDKs.

To ensure efficient management, the Topics Registry maintains detailed metadata about each topic, including creation time, owner, access controls, and associated data.

### Topics Ownership

Topic ownership is a fundamental concept in the DPSN network. This subsection outlines the principles and mechanisms related to topic ownership.

#### Core Functionalities

* **Topic Assignment:** The process of assigning topic ownership to a specific entity or address.
* **Ownership Transfer:** The ability to transfer topic ownership from one entity to another.
* **Ownership Verification:** Mechanisms for verifying the ownership of a specific topic.

#### Technical Implementation

Topic ownership is recorded on the Topics Registry as part of the topic metadata. Ownership transfers are executed through on-chain transactions, ensuring transparency and immutability.

To prevent unauthorized ownership transfers, cryptographic signatures are used to verify the authenticity of ownership transfer requests.

### Topics Transfer

Topic transfer enables the exchange of topic ownership between different entities. This subsection outlines the process and considerations for topic transfers.

#### Core Functionalities

* **Transfer Initiation:** The process of initiating a topic transfer from the current owner to a new owner.
* **Transfer Agreement:** Establishment of terms and conditions for the topic transfer, including transfer fee, if applicable.
* **Transfer Completion:** Finalization of the topic ownership transfer and updating the Topics Registry.

#### Technical Implementation

Topic transfers are executed through on-chain transactions, ensuring transparency and immutability. The Topics Registry is updated to reflect the new topic owner.

To facilitate smooth topic transfers, escrow mechanisms or smart contracts can be employed to handle payment and ownership transfer conditions.


# Configurator

The Configurator is responsible for mapping topics to specific clusters within the network. This intelligent system optimizes message routing, load balancing, and fault tolerance.

#### Core Functionalities

* **Topic-to-Cluster Mapping:** The Configurator dynamically assigns topics to clusters based on factors such as network load, cluster capacity, and topic characteristics (e.g., message volume, rate).
* **Load Balancing:** By distributing topics across multiple clusters, the Configurator ensures even workload distribution and prevents system bottlenecks.
* **Fault Tolerance:** The Configurator maintains redundancy in topic-to-cluster mappings to mitigate the impact of cluster failures.
* **Dynamic Adjustments:** The Configurator continuously monitors network conditions and adjusts topic-to-cluster mappings as needed to optimize performance and reliability.

#### Technical Implementation

The Configurator is a distributed system consisting of multiple nodes that collaborate to maintain a consistent view of the network topology and topic-to-cluster mappings. Consensus algorithms are employed by the subscribers which provides DPSN very different architecture than standard consensus based infrastructures that always have speed bottlenecks.

To optimize performance, the Configurator utilizes machine learning techniques to analyze network traffic patterns and predict future load. This information is used to proactively adjust topic-to-cluster mappings.

#### Security and Privacy

The Configurator employs robust security measures to protect the integrity and confidentiality of topic-to-cluster mappings. Access to the Configurator is restricted to authorized nodes, and communication between Configurator nodes is encrypted.

To preserve user privacy, the Configurator avoids collecting or processing sensitive user data. Topic-to-cluster mappings are based on aggregate network metrics and do not reveal information about individual users or messages.

### Topic-to-Cluster Mapping

The Configurator plays a pivotal role in determining the optimal placement of topics within the DPSN network. This subsection delves into the intricacies of topic-to-cluster mapping.

#### Core Functionalities

* **Topic Assignment:** Assigning newly created topics to specific clusters based on various factors such as network load, cluster capacity, and topic characteristics.
* **Topic Reassignment:** Dynamically relocating topics to different clusters in response to changing network conditions or to improve performance.
* **Load Balancing:** Distributing topics evenly across clusters to optimize resource utilization and prevent overloading.
* **Fault Tolerance:** Ensuring redundancy by mapping topics to multiple clusters to mitigate the impact of cluster failures.


# Clusters

The DPSN network is composed of multiple interconnected clusters. Each cluster is a geographically distributed group of nodes that work collaboratively to process and disseminate messages. This decentralized architecture enhances fault tolerance, scalability, and performance.

#### Core Functionalities

* **Message Processing:** Nodes within a cluster receive, process, and store messages.
* **Message Dissemination:** Processed messages are replicated across multiple nodes within the cluster to ensure availability and fault tolerance.
* **Load Balancing:** Messages are distributed evenly across nodes within a cluster to optimize performance and prevent bottlenecks.

#### Technical Implementation

Each cluster is a self-contained network with its own communication protocol. This enables clusters to operate independently, improving overall system resilience.

To enhance performance, clusters can be organized into hierarchical structures, with multiple sub-clusters within a larger cluster. This approach facilitates load balancing and reduces communication overhead.

#### Security and Privacy

Clusters employ robust security measures to protect message integrity and confidentiality. Encryption, authentication, and access controls are essential components of cluster security.

To preserve user privacy, clusters avoid storing or processing sensitive user data. Message content is encrypted, and access to message data is restricted to authorized nodes.

By providing a distributed and fault-tolerant platform for message processing and dissemination, clusters form the backbone of the DPSN network.

### Fault Tolerance

Fault tolerance is a critical aspect of the DPSN architecture, ensuring the continued operation of the network even in the face of failures.

#### Core Functionalities

* **Node Redundancy:** Maintaining multiple nodes within a cluster to provide redundancy and backup capabilities.
* **Data Replication:** Replicating data across multiple nodes to prevent data loss in case of node failures.
* **Error Detection and Correction:** Implementing mechanisms to detect and correct errors in data transmission and processing.
* **Failure Recovery:** Developing strategies for recovering from node or cluster failures, including automatic failover and restart procedures.

#### Technical Implementation

Clusters employ distributed consensus algorithms to achieve fault tolerance. These algorithms ensure data consistency and availability even in the presence of node failures.

To enhance fault tolerance, clusters can be geographically dispersed to reduce the risk of simultaneous failures. Additionally, network-level redundancy can be implemented to protect against network outages.

#### Security and Privacy

Fault tolerance mechanisms do not compromise security or privacy. Data replication and recovery procedures are designed to protect sensitive information.

By incorporating robust fault tolerance measures, the DPSN network ensures high availability and resilience.

### Scalability

The DPSN network is designed to handle increasing workloads and accommodate growing numbers of users and devices.

#### Core Functionalities

* **Horizontal Scaling:** The ability to add new nodes or clusters to increase processing capacity.
* **Load Balancing:** Distributing workload evenly across nodes and clusters to prevent performance bottlenecks.
* **Sharding:** Partitioning data and processing tasks across multiple clusters to improve scalability and performance.
* **Capacity Planning:** Predicting future network growth and planning for necessary infrastructure expansion.

#### Technical Implementation

The DPSN architecture supports horizontal scaling by allowing for the addition of new nodes and clusters as needed. Load balancing mechanisms are employed to distribute incoming traffic evenly across the network.

To handle large datasets and high transaction volumes, sharding can be implemented to partition data and processing tasks across multiple clusters.

#### Security and Privacy

Scalability measures should not compromise security or privacy. As the network grows, it is essential to maintain strong security controls and data protection practices.

By incorporating scalable design principles, the DPSN network can adapt to changing demands and ensure long-term sustainability.

### Message Replication

Message replication is a fundamental strategy for ensuring data reliability and availability within DPSN clusters.

#### Core Functionalities

* **Data Redundancy:** Creating multiple copies of a message and distributing them across multiple nodes within a cluster.
* **Replication Factor:** Determining the optimal number of replicas for each message based on reliability and performance requirements.
* **Replica Synchronization:** Maintaining consistency among message replicas across different nodes.
* **Conflict Resolution:** Handling situations where multiple replicas of a message are updated with conflicting data.

#### Technical Implementation

Message replication is implemented using distributed consensus algorithms to ensure data consistency and availability. Replication factors can be adjusted based on the importance of the data and the desired level of fault tolerance. DPSN implements a unique consensus confirmation mechanism on subscribers' side too to allow flexibility of subscribers for taking action based on urgency vs accuracy requirement of the message.

To optimize performance, message replication is combined with data compression and deduplication techniques.

#### Security and Privacy

Message replication should not compromise data confidentiality or integrity. Encryption and access controls can be used to protect replicated data.


# Publishers and Subscribers

### Publishers

Publishers are entities within the DPSN network that generate and disseminate messages. They play a crucial role in creating and managing topics.

#### Core Functionalities

* **Topic Creation:** Publishers can create new topics by submitting a transaction to the Topics Registry. Before starting, register on DPSN Dashboard to start registration as publisher and obtain your **publisher access token** (Auto-generated on registration) by clicking the top-right menu → Access Tokens to view your publisher access token.
* **Message Creation and Publication:** Publishers generate messages and associate them with specific topics. Messages are then sent to the Configurator for routing to appropriate clusters.
* **Topic Management:** Publishers have the ability to modify topic attributes, such as pricing for subscribing to them and access control.
* **Authentication and Authorization:** Publishers are required to authenticate their identity and possess the necessary permissions to publish messages on a particular topic.

#### Technical Implementation

Publishers interact with the DPSN network through an API or SDK that provides access to core functionalities. To ensure security and integrity, publishers employ cryptographic keys for authentication and message signing.

To optimize performance, publishers can batch multiple messages into a single transaction, reducing network overhead. Additionally, publishers can leverage compression techniques to reduce message size.

#### Security and Privacy

Publishers are responsible for protecting their access tokens and ensuring the security of their message content. By encrypting messages, publishers can safeguard sensitive information.

To maintain user privacy, publishers should avoid including personally identifiable information in message content. Additionally, publishers should comply with relevant data privacy regulations.

By creating and disseminating messages, publishers contribute to the dynamic and informative nature of the DPSN network.

### Topic Acquisition

Topic acquisition is the process by which publishers obtain ownership of specific topics within the DPSN network.

#### Core Functionalities

* **Topic Discovery:** Identifying available topics for acquisition.
* **Topic Bidding:** Participating in a bidding process for desired topics, if applicable.
* **Topic Purchase:** Acquiring topic ownership through payment of the required tokens or other agreed-upon terms.
* **Topic Registration:** Registering the acquired topic with the Topics Registry.

#### Technical Implementation

Topic acquisition is implemented through various mechanisms, including auctions, direct purchase, or a combination thereof. Smart contracts are being used to automate the acquisition process and ensure transparency.

To facilitate topic discovery, a marketplace or directory of available topics will be established.

#### Security and Privacy

Topic acquisition processes prioritizes security and transparency. Cryptographic mechanisms will be used to protect bidding information and ownership transfer.

Privacy considerations are taken into account, especially when handling sensitive topic information.

### Message Publishing

Message publishing is the core function of publishers within the DPSN network.

#### Core Functionalities

* **Message Creation:** Generating message content and associated metadata.
* **Message Formatting:** Structuring messages according to defined standards and protocols.
* **Message Signing:** Authenticating message origin and integrity through digital signatures.
* **Message Routing:** Submitting messages to the Configurator for routing to appropriate clusters.

#### Technical Implementation

Publishers can utilize various tools and libraries to create and format messages efficiently. Message content can be structured using JSON, XML, or other suitable formats.

To ensure data integrity and authenticity, publishers should employ cryptographic techniques to sign messages.

#### Security and Privacy

Message publishing processes should prioritize security and privacy. Encryption can be used to protect sensitive message content.

To maintain user privacy, publishers should avoid including personally identifiable information in message content.

By effectively publishing messages, publishers contribute to the information flow within the DPSN network and create value for subscribers.

### Subscribers

Subscribers are entities within the DPSN network that consume messages published on specific topics. They play a crucial role in driving the value and utility of the network.

#### Core Functionalities

* **Topic Subscription:** Subscribers can subscribe to one or more topics to receive corresponding messages. Before starting, register on DPSN Dashboard to start registration as subscriber and obtain your subscriber **access token** (Auto-generated on registration) by clicking the top-right menu → Access Tokens to view your subscriber access token.
* **Message Consumption:** Subscribers receive messages from multiple clusters to enhance reliability and fault tolerance.
* **Message Processing:** Subscribers process received messages based on their specific requirements and applications.
* **Authentication and Authorization:** Subscribers must authenticate their identity and possess the necessary permissions to subscribe to specific topics.

#### Technical Implementation

Subscribers interact with the DPSN network through an API or SDK that provides access to subscription and message consumption functionalities. To optimize performance, subscribers can leverage asynchronous messaging patterns to handle high message volumes.

Subscribers can employ filtering mechanisms to select specific messages based on content or other criteria. This allows subscribers to focus on relevant information and reduce processing overhead.

Subscriber SDKs also implement the consensus mechanisms to allow the the option of chosing speed vs accuracy of the messages received.

#### Security and Privacy

Subscribers should protect their access tokens and ensure the security of their message consumption processes. By encrypting sensitive data, subscribers can safeguard their information.

To maintain user privacy, subscribers should handle message content responsibly and avoid sharing personal information without explicit consent. Additionally, subscribers should comply with relevant data privacy regulations.

### Subscription Options

Subscribers have various options for subscribing to topics within the DPSN network. This subsection outlines the different subscription models.

#### Core Functionalities

* **Topic-based Subscription:** Subscribing to specific topics to receive related messages.
* **Wildcard Subscription:** Subscribing to a pattern of topics using wildcard characters.
* **Filtered Subscription:** Subscribing to a subset of messages based on specific criteria.
* **Subscription Management:** Managing subscriptions, including adding, modifying, and removing subscriptions.

#### Technical Implementation

Subscribers can utilize APIs or SDKs to manage their subscriptions. The DPSN network supports different subscription models to accommodate diverse user needs.

To optimize performance, subscribers can leverage subscription filtering to reduce the volume of irrelevant messages.

#### Security and Privacy

Subscription information should be protected to prevent unauthorized access. Subscribers should have control over their subscription preferences.

Privacy considerations should be taken into account when handling subscription data.

By offering flexible subscription options, the DPSN network empowers subscribers to tailor their message consumption to their specific requirements.

### Message Delivery

Efficient and reliable message delivery is a critical aspect of the subscriber experience. This subsection outlines the key elements of message delivery.

#### Core Functionalities

* **Message Reception:** Receiving messages from multiple clusters to enhance reliability.
* **Message Validation:** Verifying the authenticity and integrity of received messages.
* **Message Processing:** Handling incoming messages based on subscriber-specific logic.
* **Error Handling:** Managing situations where message delivery fails or is delayed.

#### Technical Implementation

Subscribers can utilize asynchronous messaging patterns to handle incoming messages efficiently. Message queues can be used to buffer messages for later processing.

To ensure data integrity, subscribers can verify message signatures and checksums.

#### Security and Privacy

Message delivery should prioritize security and privacy. Encryption can be used to protect message content during transmission.

Subscribers should handle received messages securely and avoid exposing sensitive information.


# Facilitator Brokers

Brokers are optional components within the DPSN ecosystem that provide additional services to publishers and subscribers. They act as intermediaries, simplifying interactions with the network and offering value-added features.

#### Core Functionalities

* **Message Brokering:** Facilitators act as message brokers, aggregating messages from multiple publishers and distributing them to subscribers.
* **Data Transformation:** Facilitators can transform message content to meet specific subscriber requirements, such as data format conversion or filtering.
* **Message Filtering:** Facilitators can filter messages based on predefined criteria, reducing the volume of data delivered to subscribers.
* **Security and Compliance:** Facilitators can provide enhanced security features, such as message encryption and access control. They can also assist with compliance requirements.

#### Technical Implementation

Facilitators are typically deployed as standalone services that connect to multiple DPSN clusters. They utilize APIs to interact with the core network components.

To optimize performance, facilitators can leverage caching and asynchronous processing techniques. Additionally, they can employ load balancing to distribute incoming and outgoing traffic.

#### Security and Privacy

Facilitators must implement robust security measures to protect sensitive data and prevent unauthorized access. Encryption, authentication, and authorization are essential components of facilitator security.


# SDK

DPSN provides Software Development Kits (SDKs) for both publishers and subscribers to simplify interaction with the network. These SDKs encapsulate the complexities of DPSN's decentralized architecture, providing a user-friendly interface for message publishing, subscription, and management.

#### Core Functionalities

* **Message Creation and Publishing:** Publishers can create and publish messages using the SDK, including formatting, encryption (including FHE), and topic selection.
* **Subscription Management:** Subscribers can easily manage their subscriptions, including creating, modifying, and deleting subscriptions.
* **Message Reception and Processing:** Subscribers can receive, process, and decrypt (including FHE decryption) messages using the SDK.
* **Error Handling:** The SDK provides mechanisms for handling network errors, message delivery failures, and other exceptions.
* **Security:** SDKs incorporate security best practices, including key management, authentication, and authorization.
* **Speed vs Accuracy:** DPSN icnorporates unique consensus mechanicms that allows subscribers to take decision according to their speed and messages accuracy expectations.

#### FHE Integration

The SDKs seamlessly integrate with FHE libraries, allowing users to encrypt data before publishing, perform computations on encrypted data, and decrypt results.


# Message Publishing and Delivery

DPSN facilitates the efficient and reliable publishing and delivery of messages across its decentralized network. This section outlines the core functionalities and underlying mechanisms involved in this process.

#### Message Publishing

* **Message Creation:** Publishers generate messages containing relevant data and metadata. Messages can be structured in various formats (e.g., JSON, XML) to accommodate different data types.
* **Topic Selection:** Publishers choose the appropriate topic to which the message belongs. This ensures accurate message routing and delivery to interested subscribers.
* **Message Signing:** Publishers sign messages with their private keys to authenticate their identity and ensure message integrity.
* **Message Submission:** Signed messages are submitted to the Configurator, which routes them to the designated clusters.

#### Message Delivery

* **Message Routing:** The Configurator determines the optimal clusters for message delivery based on factors such as topic mapping, network load, and node availability.
* **Message Replication:** Messages are replicated across multiple nodes within the target clusters to enhance reliability and fault tolerance.
* **Message Delivery to Subscribers:** Subscribers subscribed to the relevant topic receive copies of the message from multiple clusters.
* **Message Validation:** Subscribers verify the authenticity and integrity of received messages using the publisher's public key.
* **Message Processing:** Subscribers process the received messages according to their specific applications and requirements.

#### Quality of Service

DPSN supports various quality of service (QoS) levels to meet diverse application needs:

* **At Least Once Delivery:** Guarantees that a message is delivered at least once, but duplicates may occur.
* **At Most Once Delivery:** Delivers a message at most once, but there's a risk of message loss.
* **Exactly Once Delivery:** Ensures that a message is delivered exactly once, providing strong consistency guarantees.

By offering flexible message publishing and delivery mechanisms, DPSN empowers publishers and subscribers to effectively exchange information within the network.


# Subscription Management

Effective subscription management is essential for optimizing the subscriber experience within the DPSN network. This section outlines the core functionalities and mechanisms related to subscription management.

#### Core Functionalities

* **Topic Subscription:** Subscribers can subscribe to specific topics or patterns of topics to receive relevant messages.
* **Subscription Creation:** Subscribers initiate subscription requests to the Configurator, specifying the desired topics.
* **Subscription Modification:** Subscribers can modify existing subscriptions by adding, removing, or updating subscribed topics.
* **Subscription Termination:** Subscribers can terminate subscriptions to stop receiving messages for specific topics.
* **Subscription Confirmation:** The Configurator provides confirmation of successful subscription creation or modification.

#### Subscription Models

DPSN supports various subscription models to cater to different user requirements:

* **Push-based Subscriptions:** Subscribers receive messages proactively from publishers.
* **Pull-based Subscriptions:** Subscribers actively request messages from the network.
* **Hybrid Subscriptions:** A combination of push and pull models to optimize message delivery.

#### Security and Privacy

Subscription management incorporates robust security measures to protect user privacy and prevent unauthorized access. Encryption and authentication mechanisms are employed to secure subscription information.


# Security Considerations

Security is a paramount concern in any decentralized system. DPSN employs a multi-layered security approach to protect the network, its participants, and the data transmitted.

#### Cryptographic Mechanisms

* **Message Encryption:** Messages are encrypted using strong cryptographic algorithms to protect their confidentiality.
* **Digital Signatures:** Publishers sign messages to authenticate their identity and ensure message integrity.
* **Key Management:** Secure key management practices are implemented to protect private keys and public key infrastructure.

#### Access Control

* **Authentication:** Users are required to authenticate their identities before accessing network resources.
* **Authorization:** Access to specific network functions and data is granted based on user roles and permissions.
* **Role-Based Access Control (RBAC):** Defines user roles and assigns permissions accordingly to enforce granular access control.

#### Network Security

* **Distributed Denial of Service (DDoS) Protection:** Implements measures to mitigate DDoS attacks, such as rate limiting, traffic filtering, and distributed load balancing.
* **Secure Communication:** Utilizes encrypted communication channels to protect data in transit.
* **Node Security:** Employs robust security practices for network nodes, including firewalls, intrusion detection systems, and regular security audits.

#### Data Privacy

* **Data Minimization:** Collects only essential data and avoids unnecessary data collection.
* **Data Anonymization:** Processes data in a way that removes personally identifiable information by providing various encryption methods.
* **Privacy by Design:** Incorporates privacy considerations into the system architecture from the outset.


# Topic Ownership and Access Control

#### Topic Ownership

* **Topic Creation:** Users can create new topics by providing a unique identifier and relevant metadata.
* **Ownership Assignment:** Upon creation, topic ownership is assigned to the creator.
* **Ownership Transfer:** Topic ownership can be transferred to other users through secure and verifiable processes.
* **Ownership Verification:** The network provides mechanisms to verify the ownership of a specific topic.

#### Access Control

* **Topic Permissions:** Topic owners can define access permissions for different users or groups, granting read, write, or manage privileges.
* **Role-Based Access Control (RBAC):** Different user roles (e.g., publisher, subscriber, administrator) are assigned specific permissions.
* **Access Control Lists (ACLs):** Detailed access control lists can be defined to specify allowed actions for individual users or groups.
* **Inheritance:** Topic permissions can be inherited by subtopics, simplifying access management.

#### Security Considerations

* **Ownership Verification:** Strong cryptographic mechanisms are used to verify topic ownership, preventing unauthorized access.
* **Permission Enforcement:** The network strictly enforces access control rules to protect topic data and prevent unauthorized actions.
* **Key Management:** Secure key management practices are essential for managing access control credentials.


# Access token Authentication

Private key authentication is a fundamental security mechanism in DPSN, ensuring the integrity and authenticity of network participants.

#### Core Functionalities

* **Access Token Generation:**\
  Users can obtain their access tokens by signing up on the DPSN Dashboard. Once registered, an access token is automatically generated for each user. This token is used for all authenticated interactions within the network.
* **Authentication:**\
  Instead of using cryptographic signatures, users authenticate and prove their identity and ownership through their access tokens. These tokens serve as secure credentials for publishing and subscribing to topics.
* **Access Token Management:**\
  Access keys are managed by the DPSN network, eliminating the need for users to handle private key storage or cryptographic operations. Users can view, revoke, and regenerate their access tokens directly from the dashboard interface.

#### Security Considerations

* **Access token revocation:** Emphasizes the importance of protecting access tokens from unauthorized access. Provides mechanisms for recovering lost or compromised access tokens, while maintaining security. Recommends regular rotation of access tokens to mitigate security risks.

#### Additional Features

* **Multi-signature Authentication:** Allows for multiple private keys to be required for authorizing actions, enhancing security.
* **Hardware Security Modules (HSMs):** Supports the use of HSMs for storing and managing private keys securely.

By employing robust private key authentication, DPSN safeguards against unauthorized access and ensures the integrity of network operations.


# Fully Homomorphic Encryption Support

DPSN incorporates fully homomorphic encryption (FHE) as a cornerstone of its privacy-preserving architecture. FHE empowers users to perform computations on encrypted data without compromising its confidentiality. This section delves into the technical details and benefits of FHE within the DPSN ecosystem.

#### FHE Integration

DPSN seamlessly integrates FHE into its core functionalities, allowing users to encrypt data before publication and perform computations on encrypted data without compromising privacy. The FHE scheme is embedded within the DPSN SDKs, providing a transparent and user-friendly experience.

#### Encryption and Decryption

* **Data Encryption:** Users can encrypt data using FHE keys before publishing it on the DPSN network.
* **Homomorphic Operations:** The network supports scalable operations on encrypted data.
* **Decryption:** Only authorized parties possessing the decryption key can decrypt the final result of computations.

#### Security and Privacy

* **Key Management:** DPSN employs robust key management practices to protect FHE keys and prevent unauthorized access.
* **Homomorphic Error:** The network mitigates the impact of homomorphic error through error correction techniques and parameter optimization.
* **Privacy Preservation:** FHE ensures that no sensitive information is exposed during data transmission or processing.

#### Performance Optimization

* **Hardware Acceleration:** DPSN custom facilitators provides specialized hardware accelerators to optimize FHE computations, reducing latency and improving overall performance.
* **Approximation Techniques:** Employing approximation techniques to balance accuracy and computational efficiency.
* **Parallel Processing:** Distributing FHE computations across multiple nodes to enhance performance.

#### Use Cases

* **Secure Data Analytics:** FHE enables powerful data analytics without compromising data privacy.
* **Private Machine Learning:** Training and deploying machine learning models on encrypted data.
* **Secure Supply Chain:** Protecting sensitive product information and supply chain data.
* **Financial Services:** Enabling secure and private financial transactions and analysis.


# Advantages of DPSN

DPSN offers a unique combination of features and benefits that set it apart from traditional messaging systems and other decentralized platforms.

#### Decentralization and Censorship Resistance

* **Distributed Network:** DPSN's decentralized architecture eliminates single points of failure, making it highly resilient to attacks and censorship.
* **Data Sovereignty:** Users maintain control over their data, preventing unauthorized access and exploitation.
* **Openness and Transparency:** The decentralized nature promotes transparency and fosters a level playing field for all participants.

#### Scalability and Performance

* **Horizontal Scalability:** DPSN can easily scale to accommodate increasing numbers of users, messages, and data volumes.
* **High Throughput:** The network is designed to handle high-throughput messaging, enabling real-time applications.
* **Low Latency:** DPSN minimizes message delivery latency, ensuring efficient and responsive communication.

#### Security and Privacy

* **End-to-End Encryption:** Robust encryption safeguards data confidentiality throughout its lifecycle.
* **Fully Homomorphic Encryption (FHE):** DPSN's integration of FHE provides an unparalleled level of data privacy, allowing computations on encrypted data.
* **Access Control:** Granular access controls protect sensitive data and prevent unauthorized access.

#### Interoperability

* **Standard Protocols:** DPSN supports industry-standard protocols to ensure compatibility with existing systems.
* **Ecosystem Integration:** The platform can integrate with other decentralized systems and applications.

#### Cost-Efficiency

* **Reduced Infrastructure Costs:** By leveraging a decentralized network, DPSN can reduce infrastructure costs for users.
* **Token Economics:** A well-designed token economy can incentivize network participation and create value for token holders.

#### Innovation and Flexibility

* **Developer-Friendly:** DPSN provides SDKs and APIs to facilitate application development.
* **Customizable:** The platform offers flexibility in terms of message formats, QoS levels, and network configuration.
* **Ecosystem Growth:** DPSN encourages innovation and the development of new applications and services.

Through its combination of decentralization, security, performance, and flexibility, DPSN offers a compelling value proposition for a wide range of applications and industries.


# Use Cases

DPSN's decentralized, high-performance, and secure architecture positions it as a versatile platform for a wide range of applications across various industries.

#### Decentralized Finance (DeFi)

* **High-Speed Oracles:** DPSN's low latency and high throughput make it ideal for providing real-time price feeds for decentralized exchanges and other DeFi applications.
* **Decentralized Exchanges (DEXs):** By enabling rapid order matching and execution, DPSN can power high-frequency trading and improve the overall efficiency of DEXs.
* **Yield Farming and Staking:** DPSN can facilitate the distribution of rewards and incentives for yield farming and staking platforms.
* **Decentralized Derivatives:** The platform can support the creation and trading of complex financial derivatives with real-time pricing and settlement.

#### Decentralized Physical Infrastructure (DePIN)

* **Real-time Sensor Data:** DPSN can efficiently handle the massive volume of data generated by sensors in smart cities, industrial IoT, and environmental monitoring.
* **Energy Trading:** DPSN can enable peer-to-peer energy trading, facilitating the creation of decentralized energy markets.
* **Shared Economy:** The platform can support the sharing of resources like transportation, accommodation, and tools, creating new economic opportunities.
* **Supply Chain Management:** DPSN can optimize supply chain operations by enabling real-time tracking, traceability, and collaboration among stakeholders.

#### AI

* **AI Model Training:** DPSN can distribute large datasets across multiple nodes for faster and more efficient AI model training.
* **AI Inference:** By providing low-latency data transfer, DPSN can support real-time AI inference applications.
* **AI Collaboration:** DPSN can facilitate collaboration between AI models and data scientists by enabling secure and efficient data sharing.
* **Federated Learning:** DPSN can be used to create decentralized AI models by securely aggregating data from multiple sources without compromising privacy.

#### Internet of Things (IoT)

* **Industrial IoT:** DPSN can handle massive volumes of data generated by industrial sensors, enabling real-time monitoring, predictive maintenance, and optimized operations.
* **Smart Cities:** By connecting various IoT devices, DPSN can facilitate efficient urban management, including traffic control, waste management, and energy optimization.
* **Supply Chain Management:** Real-time tracking of goods and assets, from origin to destination, can be achieved through DPSN, enhancing supply chain visibility and security.
* **Environmental Monitoring:** DPSN can collect and process data from environmental sensors, enabling monitoring of air and water quality, climate change, and disaster response.

#### Social and Messaging Platforms

* **Decentralized Social Networks:** DPSN can power censorship-resistant social platforms, protecting user privacy and freedom of speech.
* **Real-time Communication:** The platform can enable fast and secure messaging applications, including chat, voice, and video communication.
* **Decentralized Content Distribution:** DPSN can facilitate efficient distribution of multimedia content, such as images, videos, and music, across a decentralized network.

#### Financial Services

* **High-Frequency Trading (HFT):** DPSN's low latency and high throughput make it ideal for executing high-speed trades, providing a competitive advantage in the financial markets.
* **Real-time Risk Management:** By processing vast amounts of market data in real-time, DPSN can help financial institutions assess and manage risks effectively.
* **Fraud Detection:** DPSN can analyze transaction patterns to identify anomalies and detect fraudulent activities, protecting financial institutions and customers.
* **Payment Systems:** The platform can support secure and efficient payment processing, enabling real-time transfers and settlements.

#### Enterprise Apps

* **Supply Chain Management:** DPSN can provide real-time visibility into supply chain operations, enabling efficient inventory management, demand forecasting, and risk mitigation.
* **IoT Data Processing:** By handling large volumes of data from IoT devices, DPSN can optimize industrial processes, predictive maintenance, and asset management.
* **Customer Relationship Management (CRM):** DPSN can enhance CRM systems by enabling real-time customer interaction, personalized marketing, and improved customer service.
* **Enterprise Messaging:** The platform can provide a secure and reliable messaging infrastructure for internal communication and collaboration within enterprises.

#### Supply Chain and Logistics

* Supply Chain Transparency: DPSN can enable real-time tracking of goods and materials throughout the supply chain, improving transparency and accountability.
* Counterfeit Prevention: By providing tamper-proof records of product origins and movements, DPSN can help combat counterfeiting.

#### Healthcare

* Electronic Health Records (EHR): DPSN can securely transfer patient health records with high speed, ensuring data privacy and interoperability.
* Telemedicine: The platform can facilitate real-time communication and data exchange between healthcare providers and patients, enabling remote consultations and monitoring.

#### Gaming

* In-Game Economies: DPSN can facilitate the creation of decentralized in-game economies, allowing players to own and trade virtual assets.
* Multiplayer Gaming: The platform can provide low-latency communication and secure data exchange for multiplayer games, enhancing the gaming experience.

By addressing the limitations of centralized systems and offering a secure, scalable, and decentralized foundation, DPSN empowers developers to build innovative applications across a wide range of industries.


# SDK Introduction

The DPSN SDK is designed to provide a seamless and secure interface for interacting with the Decentralized Publish-Subscribe Network (DPSN). With just a few lines of code, developers can integrate their applications with DPSN, leveraging its powerful features for real-time data distribution and decentralized communication.

With its focus on **value** and **simplicity**, DPSN provides a robust and scalable solution for real-time data distribution and decentralized communication.

**Why Choose DPSN?**

* **Unparalleled Value:** DPSN delivers exceptional value by offering a decentralized, high-performance, and secure infrastructure.
* **Simplified Integration:** Our SDKs are designed to be user-friendly, making integration a breeze.
* **Enhanced Security:** Benefit from advanced security features, including fully homomorphic encryption, to protect your data.
* **Scalability and Reliability:** DPSN is built to handle massive volumes of data and ensure uninterrupted service.
* **Community-Driven:** Join a vibrant community of developers and innovators who are shaping the future of decentralized data exchange.

**Key Features:**

* **Security:** The SDK prioritizes security by implementing robust authentication, encryption, and access control mechanisms.
* **Simplicity:** A sleek and intuitive API allows developers to integrate DPSN with minimal effort.
* **Accessibility:** The SDK is designed to be accessible to developers of all skill levels, regardless of their familiarity with decentralized technologies.


# Publisher

#### Prerequisites

* A DPSN account with a registered topic.
* A delegated address with appropriate permissions.
* The DPSN SDK for your preferred programming language.

#### Publishing Your Data Stream: 8 Simple Steps <a href="#publishing-your-data-stream-8-simple-steps" id="publishing-your-data-stream-8-simple-steps"></a>

**Step 1: Click "New Stream"**

Go to the [Dashboard](https://streams.dpsn.org/). Navigate to your publisher dashboard by clicking "Publish" in the header menu, then click "New Stream" to begin the publishing process.

<figure><img src="https://blog.dpsn.org/~gitbook/image?url=https%3A%2F%2F2626516989-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252FNFvFJOntSi4tCRxqnRLJ%252Fuploads%252FegyhElgCjz1TUlci58KS%252FScreenshot%25202025-06-10%2520at%25201.05.50%25E2%2580%25AFPM.png%3Falt%3Dmedia%26token%3D64e0cff3-492a-4ff5-baff-f6b30ce0af87&#x26;width=768&#x26;dpr=4&#x26;quality=100&#x26;sign=bbe526bf&#x26;sv=2" alt=""><figcaption></figcaption></figure>

**Step 2: Enter Stream Details**

Enter your stream name, stream ID, description, and pricing per event to help subscribers discover and understand your data offering. Click "Continue" when finished.

<figure><img src="https://blog.dpsn.org/~gitbook/image?url=https%3A%2F%2F2626516989-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252FNFvFJOntSi4tCRxqnRLJ%252Fuploads%252F3KA4Kh4QQNH03CTFhC1R%252FScreenshot%25202025-06-10%2520at%25201.19.27%25E2%2580%25AFPM.png%3Falt%3Dmedia%26token%3D5b85d869-2b88-4d78-8b6c-63baf208ded7&#x26;width=768&#x26;dpr=4&#x26;quality=100&#x26;sign=6f5b465a&#x26;sv=2" alt=""><figcaption></figcaption></figure>

**Step 3: Stream Creation in Progress**

DPSN will automatically provision the necessary infrastructure and configure your data pipeline. The system handles all backend setup without any manual intervention.

<figure><img src="https://blog.dpsn.org/~gitbook/image?url=https%3A%2F%2Flh7-rt.googleusercontent.com%2Fdocsz%2FAD_4nXfFVgduPXJu0SJ047fIS-ErL8pxfJwfIRgwT-H3vRVqJ2PHtr7xvTMRl0xPy6q1sFg38r8m_3Ga9nH5yGMf-qbqt0iMnpR4qlwr-0gcVXhpesnhiNwf_cOyXQproQu6d2opEZOK%3Fkey%3D6VopLbnoRPt_lnDvIcOB7w&#x26;width=768&#x26;dpr=4&#x26;quality=100&#x26;sign=72ab3d1f&#x26;sv=2" alt=""><figcaption></figcaption></figure>

**Step 4: Stream Created with Integration Guide**

Congratulations! Your stream is now created on the marketplace. You'll receive unique a topic ID, authentication tokens, and comprehensive integration documentation for your stream. You can start the integration by installing the DPSN client first.

<figure><img src="https://blog.dpsn.org/~gitbook/image?url=https%3A%2F%2F2626516989-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252FNFvFJOntSi4tCRxqnRLJ%252Fuploads%252FYL3UuPxF8T2a45yFduMd%252FScreenshot%25202025-06-10%2520at%25201.23.27%25E2%2580%25AFPM.png%3Falt%3Dmedia%26token%3Dafc5c4f9-6f11-49f9-80fe-bd86f85ac41b&#x26;width=768&#x26;dpr=4&#x26;quality=100&#x26;sign=7675ba99&#x26;sv=2" alt=""><figcaption></figcaption></figure>

**Step 5: Configure your DPSN client**

Configure the client by copying the provided code. This step ensures your system can communicate properly with the DPSN network.

<figure><img src="https://blog.dpsn.org/~gitbook/image?url=https%3A%2F%2F2626516989-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252FNFvFJOntSi4tCRxqnRLJ%252Fuploads%252FIz777CA4MDA2NJKNRCJ8%252FScreenshot%25202025-06-10%2520at%25201.28.02%25E2%2580%25AFPM.png%3Falt%3Dmedia%26token%3D2c1e17d4-ccae-4433-b2f4-f625228a0dff&#x26;width=768&#x26;dpr=4&#x26;quality=100&#x26;sign=2f326c35&#x26;sv=2" alt=""><figcaption></figcaption></figure>

**Step 6 : Get Your Access Code and Publish Data**

To authenticate with the DPSN network, copy your access code, then copy the integration code and publish the data from your system.

<figure><img src="https://blog.dpsn.org/~gitbook/image?url=https%3A%2F%2F2626516989-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252FNFvFJOntSi4tCRxqnRLJ%252Fuploads%252FSJnvnvtVSy9ha34FUfe3%252FScreenshot%25202025-06-10%2520at%25201.28.09%25E2%2580%25AFPM.png%3Falt%3Dmedia%26token%3D7f931e39-c1f6-4725-9834-2614f15d8e44&#x26;width=768&#x26;dpr=4&#x26;quality=100&#x26;sign=5d79c63d&#x26;sv=2" alt=""><figcaption></figcaption></figure>

#### Step 7: Review Process <a href="#step-7-review-process" id="step-7-review-process"></a>

Your stream will be reviewed by the DPSN team within 12 hours. You'll receive an email confirmation once your stream goes live.

Once you receive email confirmation that your stream is live, you can see your stream under the publisher dashboard. If someone has subscribed to your stream, you can check subscriber details by clicking on the "View Details" tab.

<figure><img src="/files/RHa4YfyvaqhfLn5dwrba" alt=""><figcaption></figcaption></figure>


# Subscriber

#### Prerequisites

* A DPSN account with a registered topic.
* A delegated address with appropriate permissions.
* The DPSN SDK for your preferred programming language.

#### Quick Start <a href="#quick-start" id="quick-start"></a>

**1. Browse Data Stream Marketplace**

Navigate to the[ DPSN marketplace](https://streams.dpsn.org/) to discover and subscribe to real-time data streams. Click on the Subscribe button from the homepage to see all available streams. Filter streams by categories or sort by newest first. Click "View Details" to learn more about any specific stream.

<figure><img src="https://blog.dpsn.org/~gitbook/image?url=https%3A%2F%2Flh7-rt.googleusercontent.com%2Fdocsz%2FAD_4nXc2_YpiPJCBJs2ceQRHQwkBWQg5FdcZnDmKSsif9Au-7EvEsrSAp2GDYU1nxm8gRE2jy5i_gebt7U8-Y9Wcwrg3_tNsZBcagjWIyE-K_VJEb-2prAMOIPD9WlBP-tIwb8EyxNwq4A%3Fkey%3D5tcEOgMrXnnga4cALCJZtg&#x26;width=768&#x26;dpr=4&#x26;quality=100&#x26;sign=589dab28&#x26;sv=2" alt=""><figcaption></figcaption></figure>

**2. View Stream Details**

Access comprehensive information about your selected data stream including description, availability timestamp, pricing per 1,000 events, and the unique Topic ID. The Topic ID serves as the unique identifier you'll use to access the data stream in your integration.

<figure><img src="https://blog.dpsn.org/~gitbook/image?url=https%3A%2F%2Flh7-rt.googleusercontent.com%2Fdocsz%2FAD_4nXfP22D0K74CMniHoGEkAz1t8Kjo8Aq9uw2YuB_xSNcB2qBAHbkQNdVRDST9WgdWDO00sDz2GJOO9Y5Yrthe1S1M6Om8eqgqT6NJQOFwrhJhDAKTmAbdWxAl-HAhEZ9lOLyYK_hC%3Fkey%3D5tcEOgMrXnnga4cALCJZtg&#x26;width=768&#x26;dpr=4&#x26;quality=100&#x26;sign=1b6fbad4&#x26;sv=2" alt=""><figcaption></figcaption></figure>

**3. API Access to Subscribe to the Stream**

You can access streams through our API integration. Follow the API access guide to subscribe to the specific stream of your choice.

<figure><img src="https://blog.dpsn.org/~gitbook/image?url=https%3A%2F%2Flh7-rt.googleusercontent.com%2Fdocsz%2FAD_4nXdzc4l9t1Dl6LaWUmP1eCFVFEkMZJw7eFvD758FAaca1eMpKo-8mET22o-qFdJDj5LQllArRGpUiyR_4ChuWK2-ycZ_aYrl8jkDuyijQAudrgotzAHB6y9ryhxZ0HyDdwWDFjUJiw%3Fkey%3D5tcEOgMrXnnga4cALCJZtg&#x26;width=768&#x26;dpr=4&#x26;quality=100&#x26;sign=85f0593&#x26;sv=2" alt=""><figcaption></figcaption></figure>

**4. Alternatively you can choose SDK Access method to subscribe to the stream**

Alternatively you can choose the SDK Access method to Subscribe to the Stream. Install and Configure DPSN Client to begin.

Create a new file called dpsn-integration.js and initialize the DpsnClient with your server endpoint, access token, and connection settings. Add event handlers to monitor connection status and handle any errors that occur during the connection process.

<figure><img src="https://blog.dpsn.org/~gitbook/image?url=https%3A%2F%2Flh7-rt.googleusercontent.com%2Fdocsz%2FAD_4nXdFkSgH8D6J8iC60v2lxew0zvXYVp5Td8sEbMp0jWJ8av7LHaxavBWml9qgdGcdNo31nOtpSKF5JtR_WdhrvjNGyIVjKQ2WjI7twxxrImmYVws-BOg1OEO9_wYsjrPNPiab9eS5iw%3Fkey%3D5tcEOgMrXnnga4cALCJZtg&#x26;width=768&#x26;dpr=4&#x26;quality=100&#x26;sign=dc79bddd&#x26;sv=2" alt=""><figcaption></figcaption></figure>

**5. Get Your Access Token and Integrate the Following Code**

Copy your access token from the dashboard to authenticate with the DPSN network. Use the provided details to complete your integration setup.

<figure><img src="https://blog.dpsn.org/~gitbook/image?url=https%3A%2F%2Flh7-rt.googleusercontent.com%2Fdocsz%2FAD_4nXc6WTwIYAgxIM4T_tol5P5oFR1WYJ2GqKu3aGdt38JKsA7WsEAfC2uRr78bLrXquKjLT3btMuTboKuPe0WOlvE1hRR2vJ8dqsI8rSbHaOBkSZjF0jFXcEEOn_8PD4uxqbl1Lf6Y%3Fkey%3D5tcEOgMrXnnga4cALCJZtg&#x26;width=768&#x26;dpr=4&#x26;quality=100&#x26;sign=e90d3ce&#x26;sv=2" alt=""><figcaption></figcaption></figure>


# Delegated Addresses

**Delegated addresses** are a mechanism in DPSN that allows users to grant specific permissions to other entities without compromising their main account's security. This provides a flexible and secure way to manage access to topics and other network resources.

#### Key Features of Delegated Addresses

* **Permission Delegation:** Users can grant specific permissions to delegated addresses, such as publishing messages, subscribing to topics, or managing other network resources.
* **Revocable Permissions:** Permissions can be revoked at any time, providing granular control over access.
* **Security:** Delegated addresses offer a layer of security by isolating sensitive information from the main account.
* **Flexibility:** Delegated addresses can be used for various use cases, such as managing multiple accounts, collaborating with team members, or granting access to third-party applications.

#### How Delegated Addresses Work

1. **Create a Delegated Address:** Users can create delegated addresses using the DPSN dashboard or API.
2. **Grant Permissions:** Assign specific permissions to the delegated address, such as publishing messages on certain topics or subscribing to data streams.
3. **Use the Delegated Address:** The delegated address can be used to perform actions within the DPSN network based on the granted permissions.

#### Benefits of Using Delegated Addresses

* **Enhanced Security:** By using delegated addresses, users can limit the scope of access to their DPSN accounts, reducing the risk of unauthorized actions.
* **Improved Collaboration:** Delegated addresses facilitate collaboration between team members and organizations.
* **Simplified Management:** Managing multiple accounts or granting access to third-party applications becomes easier with delegated addresses.


# 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:** While creating a new stream, set Visibility = Private Stream. Before starting, register on DPSN Dashboard to start registration as publisher and obtain your **publisher access token** (Auto-generated on registration) by clicking the top-right menu → Access Tokens to view your publisher access token.
2. **Encrypt and Send Messages:** Share the private topic ID with the intended recipient

```
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.


# 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.

```javascript
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.

```javascript
// 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.

```javascript
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);
  }
});
```


# Utility

DPSN tokens form the economic foundation of the Decentralized Publish-Subscribe Network, serving three essential functions within the ecosystem.

1. They act as gas fees, enabling subscribers to access and listen to messages on the network, ensuring efficient allocation of resources.
2. DPSN tokens are used to purchase topics, granting publishers the right to disseminate messages on specific channels, thus creating a market-driven content ecosystem.
3. DPSN tokens act as metered billing for publishers wanting to monetize their data subscription. &#x20;
4. These tokens serve as mining rewards for node runners, incentivizing the maintenance and expansion of the network's infrastructure.

This utility creates a balanced economy where token flow is directly tied to network usage, data transfer, and infrastructure support, fostering a self-sustaining and scalable decentralized communication platform.

## Guiding Principles

**Demand-Driven Emissions**:

* DPSN's token emissions are directly tied to network usage. Tokens are only released when subscribers pay for messages, ensuring that emissions correlate with actual demand.

**Sustainable Incentive Structure**:

* Node runners receive a percentage of subscriber payments, not a fixed amount of tokens.
* This percentage-based model ensures that the incentive structure remains proportional to network usage and revenue, preventing unsustainable token emissions.

**Built-in Scalability**:

* As the network grows, the token model naturally scales. Increased usage leads to more emissions, but always in proportion to the value being created and captured within the network.

**Demand-Side Incentives**:

* While our model primarily incentivizes the supply side (node runners), it indirectly benefits the demand side (subscribers) by ensuring a robust, efficient network.
* The cost-effective nature of our "pay-per-message" model for subscribers inherently encourages demand-side participation.

**Long-Term Sustainability**:

* Unlike models that rely on heavy initial token emissions or unsustainable rewards, DPSN's approach is designed for long-term viability.
* The token emission rate adjusts automatically with network usage, preventing the rapid depletion of token reserves often seen in less sustainable models.

**Balanced Ecosystem**:

* By aligning the interests of node runners, subscribers, and token holders, we create a balanced ecosystem that can sustain itself.

**Flexibility for Future Adjustments**:

* While we believe our current model is sustainable, we've built in flexibility to allow for parameter adjustments if needed, ensuring long-term adaptability.


# Token Utility Model

DPSN employs a token-based economic model designed to create a sustainable, efficient, and scalable ecosystem. DPSN tokens serve three primary functions within the network:

1. **Gas Fees**: Subscribers use tokens to pay for message reception, ensuring efficient resource allocation.
2. **Topic Purchases**: Publishers acquire tokens to buy rights for message dissemination on specific channels.
3. **Mining Rewards**: Node runners receive tokens as compensation for maintaining network infrastructure.

This multi-faceted utility creates a circular economy where token flow directly correlates with network activity, content creation, and infrastructure support. The DPSN pricing model, built on game theory principles, aims to balance these utilities by:

* Maintaining competitive pricing for subscribers
* Ensuring sustainable compensation for node runners
* Allowing for network scalability without economic disruption

By optimizing the interplay between token utility and pricing, DPSN creates a self-regulating system that aligns the interests of all participants while fostering network growth and efficiency.

Given:

* p₀ = maximum competitive price per message
* e₀ = base infrastructure cost per hour for node runners
* m = messages sent per hour

Let's define:

* p = actual price per message (needs to be determined)
* n = number of node runners
* α = percentage of revenue allocated to node runners (0 < α < 1)

### Constraints:

1. Subscriber benefit: p < p₀
2. Node runner revenue: (α × p × m) / n > e₀

### Objective:

Maximize total network value (V) = Subscriber Surplus + Node Runner Profit

where

**Subscriber Surplus** is the difference between the maximum subscribers are willing to pay (**p₀**) and the actual price (**p**), and&#x20;

**Node Runner Profit** is the compensation to node runners based on message volume and infrastructure costs.

`V = (p₀ - p)m + (α × p × m - n × e₀)`

### Optimal Solution:

To find the optimal p and α, we need to maximize V subject to the constraints.Solving the node runner profit constraint:

```
(α × p × m) / n > e₀ 
or, α > (n × e₀) / (p × m)
```

Optimal α (minimizing p while ensuring node runner profit):

```
α* = (n × e₀) / (p × m)
```

Substituting into the objective function:

```
V = (p₀ - p)m + (e₀ × n - n × e₀) 
or, V = (p₀ - p)m
```

To maximize V, we want p to be as low as possible while still satisfying: p > (n × e₀) / (α × m)Therefore, the optimal price p\* is just above this lower bound:p\* = (n × e₀) / (α × m) + εWhere ε is a small positive number to ensure strict inequality.

### Final Model:

* Optimal price:&#x20;

`p* = (n × e₀) / (α × m) + ε`

* Optimal revenue share:&#x20;

`α* = (n × e₀) / (p* × m)`

This model ensures:

1. p\* < p₀ (subscriber benefit)
2. (α\* × p\* × m) / n > e₀ (node runner profit)

The network can adjust n and α to find the optimal balance between competitive pricing and node runner incentives.

### **How the Model Balances the Ecosystem:**

* **Subscribers** benefit by paying less than the maximum they are willing to (p₀), while still ensuring the network's long-term viability.
* **Node Runners** are compensated above their costs (**e₀**) to keep the network operational and scalable.
* **Network Growth** is supported by adjusting **n** (number of nodes) and **α** (revenue share) to ensure sustainable scalability without economic disruption.

### Examples

This self-regulating model fosters a circular token economy, aligning incentives across participants (subscribers, publishers, and node runners) and ensuring that as the network grows, both performance and economic sustainability are maintained.

Examples of various sample configurations below:

<figure><img src="/files/whp2NTxxxziXFXaesqJv" alt=""><figcaption><p>DPSN Token Pricing Model Calculations</p></figcaption></figure>


# DIP1: Stateless Message Routing in DPSN

Proposal to remove dependencies for topic lookup on chain every time a message is published.

### Overview

This document outlines the technical flow for routing messages in the Decentralized Publish-Subscribe Network (DPSN). The proposed system ensures that nodes remain stateless or minimally dependent on external network lookups by leveraging cryptographic signatures for ownership verification and message integrity. This paper details the algorithms and formulas used in the encryption methods employed in the system.

### Flow Description

#### 1. Topic Purchase and Address Generation

* **Publishers** can purchase topics identified by a **topic name** that acts as vanity for the topic.&#x20;
* The **topic address** is generated using the following components:
  * **Creation Time (T)**: The timestamp when the topic is created.
  * **Publisher Address (P)**: The unique blockchain address of the publisher.
  * **Nonce (N)**: A unique nonce or timestamp to prevent collisions.
* **Concatenation**: These components are concatenated into a single string:

  ```javascript
  message_to_sign = P + Vanity_Name + T + N
  ```
* **Signature Generation**: The publisher signs the concatenated message using their private key (SK). The signature generation process can be represented as:

  ```javascript
  codeSignature (S) = Sign(SK, message_to_sign)
  ```
* **Topic Address Generation**: The topic address (A) is generated by hashing the concatenated message along with the signature using a cryptographic hash function (e.g., SHA-256):

  ```javascript
  codeA = Hash(message_to_sign + S)
  ```

#### 2. On-Chain Storage

* All relevant data is stored on-chain, including:
  * **Topic Name**
  * **Topic Address (A)**
  * **Publisher Address (P)**
  * **Creation Time (T)**
  * **Signature (S)**

#### 3. Message Sending

* When a publisher sends a message, they provide:
  * **Topic Name**
  * **Topic Address (A)**
* **Message Verification**: DPSN nodes reconstruct the original message to verify the publisher's signature:

  * Reconstruct the original message string:

  ```javascript
  reconstructed_message = P + Vanity_Name + T + N
  ```
* **Signature Verification**: The nodes verify the signature using the corresponding public key (PK) of the publisher:

  ```javascript
  is_valid_signature = Verify(PK, reconstructed_message, S)
  ```

#### 4. Node Broadcasting and Metering

* Each node broadcasts the publisher’s data, excluding the actual content of messages sent. This serves multiple purposes:
  * **Metering System**: To track usage and validate actions within the network.
  * **Incentive Mechanism**: To reward nodes for participation and raise alerts for any potential bad actors by monitoring unusual patterns.

#### 5. SDK Message Verification

* The Software Development Kits (SDKs) used by publishers and subscribers perform an additional verification step. Before consuming messages:

  * Validate the message by checking the signature against the topic address and publisher data:

  ```css
  if is_valid_signature:
      Process(message)
  ```
* This ensures a double verification process to maintain the integrity of the messages being processed.

### Algorithms and Formulas Used

#### Cryptographic Hash Function

* **SHA-256**: A cryptographic hash function used to generate the topic address. It takes an input and produces a fixed-size string of bytes. The formula can be expressed as:

  ```scss
  codeHash(input) = H
  ```

  Where:

  * **input** = concatenated message string and signature
  * **H** = 256-bit hash value

#### Digital Signature Algorithm

* **Signing**:

  * Given a private key (SK) and a message (M), the signature (S) is generated as:

  ```scss
  codeS = Sign(SK, M)
  ```
* **Verification**:

  * Given a public key (PK), message (M), and signature (S):

  ```scss
  codeis_valid_signature = Verify(PK, M, S)
  ```

###


# DIP2: Integration of DPSN with Model Context Protocol (MCP)

\
**Author(s)**: Sanil\
**Status**: Draft\
**Type**: Standards Track\
**Created**: March 13, 2025\
\
This proposal outlines the integration of the Decentralized Pub/Sub Network (DPSN) with the Model Context Protocol (MCP) to enhance data accessibility for AI agents and decentralized applications (dApps). By bridging DPSN’s push-based, real-time data streams with MCP’s standardized pull/push interface, we enable seamless consumption of decentralized data without requiring application-level code changes. This DIP introduces a modular MCP bridge to index and serve DPSN streams, facilitating broader adoption and interoperability within the DPSN ecosystem.

### Motivation

\
DPSN provides a decentralized, high-throughput pub/sub system for real-time data streaming, but its push-based nature limits compatibility with pull-based AI agents and dApps prevalent in Web3. Developers face challenges adapting to new streams, often requiring code modifications that hinder scalability. The Model Context Protocol (MCP), with its ability to support both pull-based requests and push-based Server-Sent Events (SSE), offers a standardized solution. Integrating DPSN with MCP addresses these issues by:

* Enabling pull-based access to DPSN streams for broader compatibility.
* Allowing no-code addition of custom streams via configuration.
* Enhancing data querying and indexing for real-time applications.

### Specification

#### Overview

The integration introduces an MCP Bridge that subscribes to DPSN streams, buffers data, and exposes it via MCP-compliant tools and SSE streams. This bridge will be implemented as a reusable component within the DPSN SDK.

#### Components

1. **DPSN Stream Subscription**
   * The MCP Bridge subscribes to specified DPSN topics (e.g., price\_feed) using the DPSN SDK’s subscribe method.
   * Example: dpsn.subscribe("price\_feed", callback).
2. **Data Buffering**
   * Incoming messages are stored in an in-memory buffer (e.g., Redis or local cache), configurable for size (e.g., last 100 messages) or time (e.g., 5-minute window).
   * Structure: { topic: string, messages: \[{ data: any, timestamp: number }] }.
3. **MCP Interface**
   * **Pull-Based Tools:**
     * get\_latest\_message(topic: string): Returns the most recent message from the buffer.
     * get\_messages\_since(topic: string, since: number): Returns messages since a timestamp.
   * **Push-Based SSE:** Streams real-time updates via /events/topic endpoints.
   * Implementation: MCP server exposes RESTful API and SSE channels.
4. **Configuration**
   * Applications specify subscribed topics in a config file (e.g., JSON/YAML):json

     ```json
     {
       "dpsn_streams": ["price_feed", "sensor_data"]
     }
     ```

### Technical Requirements

* **DPSN SDK**: v1.0.0 or higher for stream subscription and publishing.
* **MCP Server**: Compatible with MCP v1.x, supporting REST and SSE.
* **Latency**: Sub-100ms end-to-end delivery from DPSN to MCP client.
* **Scalability**: Handle 10,000 concurrent subscribers per topic.

### Rationale

This integration balances DPSN’s push-based efficiency with MCP’s pull/push flexibility, addressing the needs of diverse Web3 applications:

* **Compatibility**: Supports existing MCP-based agents without requiring them to adopt a pub/sub model natively.
* **Simplicity**: No-code stream additions reduce developer friction compared to manual API integrations.
* **Performance**: Buffering and indexing optimize data access while preserving DPSN’s low-latency strengths.

Alternatives considered:

* **Direct MCP Subscriptions**: Bypassing a bridge increases complexity for MCP clients; rejected for scalability concerns.
* **Centralized Middleware**: Conflicts with DPSN’s decentralized ethos; discarded.

### Backwards Compatibility

This DIP introduces no breaking changes to existing DPSN implementations. Applications using DPSN directly remain unaffected, while those adopting the MCP bridge gain enhanced functionality. Legacy systems can opt out of MCP integration without disruption.

### Test Cases

1. Stream Subscription: Subscribe to test\_feed, publish 10 messages, verify MCP bridge buffers all 10.
2. Pull Access: Call get\_latest\_message("test\_feed"), confirm latest message matches DPSN stream.
3. Push Access: Connect to SSE /events/test\_feed, publish 5 messages, verify real-time delivery.
4. Custom Stream: Publish to new topic custom\_feed, update config, confirm subscription without restart.

### Implementation

#### Milestones

1. MCP Bridge Development: Build and test bridge component (ETA: March 20, 2025).
2. DPSN SDK Integration: Add MCP support to SDK (ETA: March 25, 2025).
3. Documentation & Release: Update DPSN docs with DIP-1 and sample code (ETA: March 30, 2025).

#### Reference Implementation

javascript

```javascript
const { DPSNClient, MCPBridge } = require('dpsn-sdk');
const client = new DPSNClient();
const bridge = new MCPBridge(client);

bridge.subscribe(["price_feed"]);
bridge.startMcpServer({ port: 8080 });

// MCP Tool Example
bridge.addTool({
  name: "get_latest_message",
  execute: async (topic) => bridge.buffer[topic]?.slice(-1)[0]?.data
});
```

#### Security Considerations

* **Data Integrity**: DPSN’s decentralization ensures tamper-resistant streams; MCP bridge validates incoming data.
* **Access Control**: Optional authentication (e.g., API keys) for MCP endpoints to restrict sensitive streams.
* **Denial of Service**: Rate limiting on MCP server to mitigate flood attacks.


# DIP-3: Standardizing DPSN AVS for Enhanced Security and Reliability

**Author(s)**: Sanil\
**Status**: Draft\
**Type**: Standards Track\
**Created**: March 14, 2025

### Abstract

This proposal introduces a standardized framework for **Actively Validated Services (AVS)** within the Decentralized Pub/Sub Network (**DPSN**) to improve security and reliability. By implementing a staking mechanism, DPSN nodes acting as AVS validators are incentivized to validate messages honestly, with penalties (slashing) enforced for malicious behavior such as tampering or censorship. This DIP outlines message validation, fraud detection, and dispute resolution processes to ensure a trustless, decentralized network for real-time data streaming.

### Motivation

DPSN’s pub/sub model excels at delivering real-time data but lacks robust mechanisms to ensure node honesty and message integrity. Without economic incentives, the network is susceptible to malicious nodes that could tamper with or censor messages. This proposal addresses the following issues:

* **Security**: A staking mechanism deters malicious behavior by imposing financial penalties.
* **Standardization**: A formalized validation process ensures consistency across all nodes.
* **Reliability**: Enhanced trust in message propagation supports critical Web3 applications.

### Specification

#### System Architecture

**Actors**

* **Publishers**: Entities submitting messages to DPSN nodes.
* **Subscribers**: Entities receiving validated messages from DPSN nodes.
* **DPSN Nodes**: Nodes that forward and validate messages, running local AVS validator services.
* **Staking Contract**: A smart contract managing node stakes, slashing, and fraud proofs.

**Flow**

1. **Message Submission**: A publisher sends a message to a DPSN node.
2. **Validation**: The node verifies the message’s integrity and authenticity (e.g., via digital signatures).
3. **Proof Generation**: The AVS validator generates a cryptographic verification proof.
4. **Propagation**: The node signs and forwards the message with the proof to its peers.
5. **Subscriber Delivery**: Subscribers receive the message along with its proof.
6. **Fraud Detection**: Nodes monitor for tampering or censorship and submit fraud proofs if detected.
7. **Slashing**: Upon validation of a fraud proof, the staking contract slashes the malicious node’s stake.

### Technical Details

* **AVS Validator**:
  * Runs locally on each DPSN node.
  * Verifies message signatures and ensures proper propagation.
  * Generates cryptographic proofs for validation.
* **Staking Contract**:
  * Requires nodes to stake tokens to participate.
  * Supports functions like stakeTokens(amount), submitFraudProof(nodeId, proof), and slashStake(nodeId).
* **Fraud Proofs**:
  * Submitted for detected tampering (e.g., signature mismatch) or censorship (e.g., failure to propagate).
  * Includes a dispute period during which accused nodes can respond.
* **Dispute Resolution**:
  * Accused nodes may submit counter-evidence within a defined timeframe.
  * Valid fraud proofs result in stake slashing; invalid claims are dismissed.

### Requirements

* **DPSN SDK**: Version 1.0.0 or higher with AVS extensions.
* **Latency**: Validation and propagation must complete in under 100ms.
* **Scalability**: Must support over 10,000 concurrent subscribers per topic.

### Rationale

The staking mechanism aligns node incentives with network integrity by making malicious actions financially costly. Alternatives considered include:

* **Reputation Systems**: Easily manipulated and less secure than staking.
* **Centralized Validation**: Undermines decentralization and was rejected.
* **No Incentives**: Leaves the network vulnerable to Sybil attacks and was deemed insufficient.

This vendor-agnostic approach ensures DPSN can integrate with various staking providers, maintaining flexibility and decentralization.

### Backwards Compatibility

Nodes must run AVS validators to participate in the validated network segment. Legacy nodes without AVS can operate in an unvalidated segment but may experience reduced trust and functionality.

### Test Cases

1. **Honest Propagation**: A message is validated, propagated, and received with a valid proof.
2. **Tampering Detection**: An altered message triggers a fraud proof, leading to stake slashing after dispute resolution.
3. **Censorship Detection**: A non-forwarded message results in a fraud proof and subsequent slashing.
4. **False Accusation**: An invalid fraud claim is dismissed during the dispute process.


# Branding

Our brand, DPSN, is here for you to use and build upon. These guidelines provide a simple framework for those who are working with our brand.

### DPSN Logotype

The logotype is a crucial element of our visual identity. To establish and maintain recognition, our logo should always be reproduced consistently. It should be clearly visible, not crowded by other page elements, and always have clear space around it.

{% tabs %}
{% tab title="PNG" %}

<div><figure><img src="/files/8MMFVUWs6JCUNIjjy2P3" alt=""><figcaption></figcaption></figure> <figure><img src="/files/gCJ2KKE1u5kiatzzu348" alt=""><figcaption></figcaption></figure> <figure><img src="/files/xSOnu39ttfcaLfnIWowB" alt=""><figcaption></figcaption></figure> <figure><img src="/files/F3bHODpNBLA5yKthzPtG" alt=""><figcaption></figcaption></figure> <figure><img src="/files/wM3EFGd33UMjIzLxaTz2" alt=""><figcaption></figcaption></figure> <figure><img src="/files/0G9QJzb9RGA9LIsi7utB" alt=""><figcaption></figcaption></figure> <figure><img src="/files/g5oXot2cJpgGKScd1v0U" alt=""><figcaption></figcaption></figure></div>
{% endtab %}

{% tab title="SVG" %}

<div><figure><img src="/files/KDWt5z9kfhieo5zrySLm" alt=""><figcaption></figcaption></figure> <figure><img src="/files/ECENSqA3ygVJZAksHX0a" alt=""><figcaption></figcaption></figure> <figure><img src="/files/I80F1mCjpzeq0FZqvQDY" alt=""><figcaption></figcaption></figure> <figure><img src="/files/qpJ5FydEn1tsHjVF51zw" alt=""><figcaption></figcaption></figure> <figure><img src="/files/K35IOBYHJNXkls6mOe6p" alt=""><figcaption></figcaption></figure> <figure><img src="/files/NGPWRUlhfm9XW7JJbVfP" alt=""><figcaption></figcaption></figure> <figure><img src="/files/KnS7M5irRahTQBPK5aTF" alt=""><figcaption></figcaption></figure></div>
{% endtab %}
{% endtabs %}

### Fonts&#x20;

Our brand uses the following typefaces for a clean, modern, and professional tone. Please use these fonts as specified to maintain visual consistency across platforms and media.

1. **GroteskRemix**  - Used primarily for headers and impactful highlights. It gives our identity a bold and structured feel

{% file src="/files/7l0htPx4y4Xd3bBnr3yk" %}

{% file src="/files/Yt0YOQwqbrofMd4KP7LR" %}

{% file src="/files/esqQtqCCzwbFcX64LP06" %}

{% file src="/files/hYmKCWhWBjXefDwlHQgR" %}

2. **Satoshi -** Used for body text and supporting content, offering excellent legibility and a minimal aesthetic.

{% file src="/files/Ge2BXsp4PfJxWHofinb9" %}

{% file src="/files/Lxy2HsXV7zqJRmB7UFkX" %}

{% file src="/files/k2UE5rpzeu0JnUYkEwq7" %}

{% file src="/files/dzrXKsEn1shpB2glNnmW" %}

{% file src="/files/qrr23ddpSSAkm4lwksdF" %}

{% file src="/files/e5NmzywsNIkggKcj5g2D" %}

{% file src="/files/jBol1mkbpKLmlLKOboZm" %}

{% file src="/files/D569Cl2iuUrTHEWwDNMp" %}

{% file src="/files/4GTC1NkBu6T2efYyfBf1" %}

{% file src="/files/wZ5ogj0Sevo9ok5LNIQD" %}

### Brand Kit

This is your reference point for all design and brand elements.\
Follow this brand kit to use **colors, fonts, and logo** correctly and consistently.&#x20;

{% file src="/files/abhWmAXb6cN3LFvqIC3W" %}

Ensure you adhere to the guidelines in this kit when creating content or assets related to DPSN.


