๐ Midnight Easy SDK: Privacy-First Development Made Simple
This is a submission for the Midnight Network "Privacy First" Challenge
- Track: Enhance the Ecosystem + Best Tutorial
- License: Apache 2.0
- GitHub: github.com/BossChaos/midnight-easy-sdk
๐ Project Overview
I built @midnight/easy-sdk to lower the barrier for developers who want to add privacy features to their apps but don't want to become zero-knowledge cryptography experts.
The SDK wraps Midnight's cryptographic primitives in a clean TypeScript API. You get seal, verify, and decrypt operations, plus React hooks that handle loading states and error recovery out of the box.
๐ ๏ธ Tech Stack
| Layer | Technology |
|---|---|
| Language | TypeScript |
| UI Framework | React + Hooks |
| Cryptography | Midnight ZK circuits (Noir) |
| Testing | Vitest |
| License | Apache 2.0 |
๐ก Core Value
- No ZK expertise required โ Seal data, verify proofs, and decrypt results with three function calls
-
React-first design โ
useSeal,useVerify,useDecrypthooks handle all the async complexity - Selective disclosure โ Reveal only the metadata you choose, keeping the rest private
-
Drop-in installation โ
npm install @midnight/easy-sdkand you're ready to go
๐ Quick Start
npm install @midnight/easy-sdk
import { MidnightEasy } from '@midnight/easy-sdk';
const midnight = new MidnightEasy({ network: 'testnet' });
await midnight.init();
Core API
1. Seal Data
seal() creates a confidential commitment from your data. Under the hood, it generates a zero-knowledge note that hides the input while allowing later selective disclosure.
const sealed = await midnight.seal({
value: 1_000_000n,
asset: 'USDC',
owner: 'did:mad:test...',
metadata: { purpose: 'escrow' }
});
console.log(sealed.commitment); // '0xabc123...'
console.log(sealed.nullifier); // '0xdef456...'
The commitment is posted to the Midnight ledger. Observers see a hash โ not the underlying value.
2. Verify a Proof
verify() checks a zero-knowledge proof against a commitment without revealing the sealed data.
const result = await midnight.verify({
commitment: sealed.commitment,
conditions: { minValue: 500_000n, allowedAssets: ['USDC'] },
proof: userProvidedProof,
});
console.log(result.valid); // true
console.log(result.metadata); // { purpose: 'escrow' }
3. Decrypt Results
decrypt() reveals the plaintext to authorized recipients only, using Midnight's threshold decryption.
const plaintext = await midnight.decrypt({
ciphertext: transfer.encryptedResult,
recipientKey: recipient.publicKey,
threshold: 2,
});
React Hooks
For UI-driven privacy flows, the SDK provides React hooks:
import { MidnightProvider, useSeal } from '@midnight/easy-sdk/react';
function App() {
return (
<MidnightProvider network="testnet" autoConnect>
<EscrowPanel />
</MidnightProvider>
);
}
function EscrowPanel() {
const { seal, isLoading, error } = useSeal();
const handleSeal = async () => {
const result = await seal({ value: 500_000n, asset: 'USDC', owner: myDID });
console.log('Committed:', result.commitment);
};
return <button onClick={handleSeal}>Seal</button>;
}
Real-World Example: Private Escrow
// Alice seals her deposit
const deposit = await midnight.seal({
value: 500_000n, asset: 'USDC', owner: aliceDID,
metadata: { role: 'depositor' }
});
// Bob seals his acceptance
const acceptance = await midnight.seal({
value: 0n, asset: 'USDC', owner: bobDID,
metadata: { role: 'acceptor' }
});
// Contract verifies both
const valid = await midnight.verify({
commitment: deposit.commitment,
conditions: { allowedAssets: ['USDC'] }
});
Contributing
Open source under Apache 2.0. Contributions welcome:
- ๐ Improve documentation
- ๐งช Expand test coverage
- ๐ ๏ธ Add new primitives and hooks
Built for the Midnight Network "Privacy First" Challenge โ Enhance the Ecosystem & Best Tutorial tracks.
Top comments (0)