Compact Standard Library: A Practical Guide to Every Export
The article provides a practical guide to the Compact standard library, which is integrated into every Midnight project and does not require separate installation. It highlights key exports such as Maybe and Either for handling optional and union types, and MerkleTree for building privacy-preserving state structures. The guide includes working code examples and aims to help developers discover built-in functionalities they may not be aware of.
- ▪The Compact standard library is built into the compiler and does not require installation or package management.
- ▪Maybe<T> and Either<L, R> are generic types used for optional values and error handling, with specific constraints in ZK circuit contexts.
- ▪Accessing .value on a None Maybe or the wrong branch of an Either in a ZK circuit causes proof generation to fail silently.
- ▪MerkleTree<N, T> is a fixed-size, compile-time-defined Merkle tree used for privacy-preserving state commitments in ZK contracts.
- ▪The guide includes a companion repository with example contracts to help developers test and understand each standard library export.
Opening excerpt (first ~120 words) tap to expand
try { if(localStorage) { let currentUser = localStorage.getItem('current_user'); if (currentUser) { currentUser = JSON.parse(currentUser); if (currentUser.id === 3908415) { document.getElementById('article-show-container').classList.add('current-user-is-article-author'); } } } } catch (e) { console.error(e); } BossChaos Posted on May 2 Compact Standard Library: A Practical Guide to Every Export #blockchain #privacy Compact Standard Library: A Practical Guide to Every Export The Compact standard library ships with every Midnight project — you don't install it, you don't import a package manager dependency. It's just there, baked into the compiler.
…
Excerpt limited to ~120 words for fair-use compliance. The full article is at DEV.to (Top).