Skip to main content

Midnight architecture

Midnight's architecture allows decentralized applications to be deployed on any device, from a massive server to a mobile phone. If the device can run a web browser, it can run a Midnight DApp. Some of Midnight's privacy-preserving capabilities, however, can be computationally intensive. Therefore, the Midnight platform has made it possible to separate the lightweight DApp code from the cryptographic heavy lifting, leading to the architecture shown in the following diagram.

Midnight Devnet

Notice, first of all, that Midnight's contracts are described in a domain-specific language: Compact, as in making a compact with someone.

One of the outputs of the Compact compiler is collection of JavaScript/TypeScript definitions that provide a custom API for a smart contract. The compiler also produces the cryptographic materials and 'circuit' descriptions needed by the proof server to create zero-knowledge proofs, which enforce the terms of a smart contract while shielding your private data.

The compiler runs only on the DApp developer's system, not in the deployed Midnight DApp.

Midnight DApps rely on the services provided by a browser extension integrated into a special Midnight alpha version of the Lace wallet exclusive for Midnight devnet. In addition to providing a faster implementation of certain functions than would be possible in JavaScript, the extension serves as the wallet to which Midnight's tokens are assigned.

In this version of the Midnight devnet, there is one token: test DUST, abbreviated tDUST. In the devnet, the primary function of tDUST is to pay for transactions. tDUST is used for devnet testing purposes only. It has no monetary value or price and is not yet calibrated to the computational expense of transactions.

The details of a user's transaction, possibly including private data, must be communicated between the DApp and the proof server to generate a proof of the transaction's correctness, but private data is never sent to any of the other services.

Keeping in mind the desirability of shielding private information, the Midnight architecture supports a variety of deployment options. For example:

  • A DApp user could run the browser-hosted DApps, the proof server, and the client service elements on their laptop so that nothing other than Midnight inter-node traffic leaves that machine.
  • Another user could run both the proof server and the client services on their own server in an office or lab and access it over an encrypted channel from a mobile device.
  • Another user could host the proof server and the client services in the cloud (or pay a trusted third party to do it) and access them from a mobile device.
  • A user could even run the proof server on their local machine (to keep private data entirely local) while relying on always-on instances of a pub-sub indexer and a Midnight node in the cloud.

This tutorial will begin by exercising that last option, giving you instructions to run only the proof server on your system, while connecting to a pub-sub indexer and Midnight network node that Midnight has provisioned in the cloud. Later in the tutorial, instructions are provided for the first option, in which you will deploy all the client services on your system, with your own Midnight node connecting to the Midnight devnet.

Tutorial overview

In this tutorial, you will begin by learning to use Midnight DApps, then learn to compile and run them, and then have an opportunity to write a contract and parts of the code yourself. At the end of the tutorial, you should have a deeper appreciation for what Midnight has to offer and enough knowledge to be able to experiment with your own Midnight contracts and DApps.

The Compact compiler, the Docker images for the proof server and other client services, and all the TypeScript libraries you need are available at:

ArtifactLocation
Compact compilerhttps://releases.midnight.network/
Proof serverhttps://hub.docker.com/r/midnightnetwork/proof-server
Midnight-Lace Wallethttps://releases.midnight.network/
VSCode extensionhttps://releases.midnight.network/
Docker imageshttps://hub.docker.com/u/midnightnetwork
Node librarieshttps://www.npmjs.com/search?q=midnight-ntwrk

The tutorial will guide you through the process of accessing them at appropriate points in the lessons.