Midnight Providers: What They Are, Where They Live, and Why We Use Them
Midnight providers are modular, pluggable components that each handle a specific capability required for transaction construction and submission to the Midnight blockchain. The provider packages include functionality for proof generation, private state management, public data queries, and transaction balancing and submission. In plain terms, they're the toolset that powers Midnight.js's…
Midnight providers are specialized components that each tackle a specific task in the construction and submission of transactions to the Midnight blockchain. These packages contain features for proof creation, private state management, public data inquiries, and transaction balancing and submission. Collectively, they form the foundation of Midnight.js architecture. There are a total of seven provider slots, with five residing in the Midnight.js API and the remaining two within the Wallet SDK.
The five providers in the Midnight.js API include a GraphQL-based blockchain data provider, a provider that offers AES-256-GCM encrypted persistent state storage, an HTTP client for the Midnight proof server, a browser-compatible zero-knowledge artifact provider, and a Node.js filesystem-based zero-knowledge artifact provider. Additionally, there's a variation called midnight-js-dapp-connector-proof-provider, which offloads proof generation to the DApp Connector wallet instead of communicating with an HTTP proof server.
On the other hand, the two providers in the Wallet SDK manage transaction balancing and signing, as well as transaction submission to the network. These two providers are provided by the Wallet SDK, not Midnight.js itself. When a single wallet class is implemented, it can handle both slots simultaneously.
To use these providers, one would create an object called `providers` and assign each provider to its respective slot. This setup allows for an optional eighth slot, loggerProvider, for diagnostic logging, which is not mandatory but can be utilized for structured logs across the provider layer. The clean separation of providers between Midnight.js and the Wallet SDK is crucial, as it enables the swapping of wallet implementations without affecting the proof or state logic, and vice versa.
This separation simplifies the overall structure and enhances flexibility when building upon the functionalities offered by Midnight.js, such as contract deployment and circuit calls.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.