Private financial infrastructure for global commerce.
Trade globally. Reveal less.
VeilCommerce is a privacy-preserving B2B commerce platform built on the Midnight blockchain. It enables businesses to transact, escrow, invoice, and finance trade without exposing commercially sensitive information.
Global commerce requires trust between strangers. Today, that trust demands total transparency:
- Bank statements
- Customer lists
- Supplier contracts
- Financial records
- Inventory levels
Prove what matters without revealing everything else.
| Instead of revealing... | VeilCommerce proves... |
|---|---|
| Exact bank balance | ✓ Funds ≥ $50,000 |
| Full customer list | ✓ Business verified in NG |
| Exact inventory | ✓ Stock ≥ 10,000 units |
| Credit score | ✓ Score ≥ 650 |
| Financial history | ✓ Compliance score ≥ 70 |
| Module | Description | Midnight Pattern |
|---|---|---|
| BusinessRegistry | Private business identity + verification | Credence (domain-separated keys, nullifiers) |
| PurchaseOrder | Private PO lifecycle with ZK-gated flags | Private order commitments + state machine |
| Escrow | Conditional payment with ZK release | Private escrow lifecycle with commitments |
| Invoice | Verified private receivable | Private receivable commitments + settlement |
| Financing | Private invoice financing + risk proof | Private credit scoring + risk verification |
| Compliance | Programmable ZK compliance | Weighted policy evaluation + selective disclosure |
| Settlement | Final settlement record | Custom (nullifier-gated) |
| CredentialRegistry | Private credentials + selective disclosure | Credence (presentation nullifiers) |
- No private data on-chain — only
persistentHashcommitments - No linkability across roles — domain-separated key derivation
- No replay of authorizations — nullifier sets per action
- Auditable when authorized — selective disclosure via ZK
Enables customs officials, tax authorities, and trade financiers to verify on-chain compliance without exposing commercially sensitive business data:
-
Proof of Funds: Proves buyer locked $\ge
$50,000$ without revealing total bank balance. -
Proof of Compliance Score: Proves regulatory composite score
$\ge 70$ without disclosing confidential KYC/tax dossiers. - Delivery Evidence Hash: Proves carrier bill of lading matches purchase order commitment without disclosing shipping routes.
- Anti-Replay Nullifier Status: Real-time query confirming unspent release nullifier to prevent double-settlement.
- Cryptographic Audit Certificate: One-click generation and export of verifiable audit receipts signed against Midnight Preprod.
An interactive testing playground for the 5 standalone Compact circuits in circuits/:
- Live Prover & Verifier: Computes
persistentHashcommitments and evaluates in-circuit constraint assertions. - Tamper Simulation Mode: Injects adversarial witness inputs (e.g. insufficient funds, altered delivery manifest, low credit score) to visibly demonstrate on-chain assertion failure.
VeilCommerce is built on Midnight's dual-state model. Private witnesses never leave your device — public state only stores commitments, flags and nullifiers. Circuits bridge the two with persistentHash + disclose().
Stored in Compact ledger (Map/Set/Counter) and disclosed via disclose(). Readable by anyone via queryVeilLedger + indexer.
- Commitments, not preimages — e.g.
contracts/Escrow.compact:46-50escrows: Map<Bytes32,EscrowRecord>holdsamountCommit/releaseCommit(persistentHash(AmountData)contracts/Escrow.compact:66-69),contracts/Invoice.compact:36-37invoices: Map<Bytes32,Bytes32>holdstermsCommitment(amount,buyer,memo,salt)contracts/Invoice.compact:68-76 - State & flags —
EscrowState {Funded, DeliveryVerified, Released}contracts/Escrow.compact:21,InvoiceStatus,acknowledged/settled/voided/financingEligiblesets,deliveryVerifiedset - Nullifiers & counters —
usedReleaseNullifierscontracts/Escrow.compact:49,totalEscrows/totalInvoices— prevents replay without linking to identity - Derived IDs —
derivePartyId(sk)=persistentHash(["veil:escrow:party:v1", sk.bytes])contracts/Escrow.compact:59-63,issuerIdcontracts/Invoice.compact:54
Anyone can query: await queryVeilLedger("Escrow","1ceac7...") → { escrows, totalEscrows } but learns only ✓ sufficient / ✓ verified, never the preimage.
Supplied per-call via witness functions, stored in privateStateProvider (levelPrivateStateProvider pattern). Never disclosed, only used inside the prover.
Defined in frontend/src/midnight/witnesses.ts:53-56,47-51:
// contracts declare what they need — frontend provides it
witness getPartySecret(): PartySecret; // contracts/Escrow.compact:53
witness privateAmount(): Uint64; // contracts/Escrow.compact:56
witness localAmount(): Uint64; // contracts/Invoice.compact:48
witness localBuyer(): Bytes32; // contracts/Invoice.compact:49
witness localSalt(): Bytes32; // contracts/Invoice.compact:51
// frontend/src/midnight/witnesses.ts:9 — [privateState, witnessValue]
export function partySecretWitness(ctx): [state, { bytes: Uint8Array }] {
const secret = ctx.privateState.partySecret ?? persistentSecret("party"); // crypto.getRandomValues(32) + localStorage veil:identity:*
return [{ ...ctx.privateState, partySecret: secret }, { bytes: secret }];
}Persisted per-role across calls (veil:identity:* in localStorage + module cache frontend/src/midnight/witnesses.ts:170-214) so the same wallet derives stable businessId / partyId / issuerId via domain-separated persistentHash frontend/src/midnight/witnesses.ts:223-245 — no cross-role linkability.
Private witness (device) Circuit (ZK) Public ledger (chain)
────────────────── ────────────── ───────────────────
secret, amount, nonce, salt ──→ persistentHash() → commitment ──→ disclose(commitment) → Map/Set
secret + escrowId ──→ persistentHash() → nullifier ──→ disclose(nullifier) → usedReleaseNullifiers
balance, required ──→ assert(balance >= required) ──→ disclose(true/false) → ✓ Funds sufficient
Example — Escrow.createEscrow contracts/Escrow.compact:104-138:
const buyerSecret = getPartySecret(); // private witness
const amount = privateAmount(); // private witness
const amountCommit = persistentHash<AmountData>({amount, salt: nonce}); // computed in-circuit
escrows.insert(disclose(escrowId), disclose(EscrowRecord{ buyer: derivePartyId(buyerSecret), amountCommit, ... }));
Example — Invoice.issue contracts/Invoice.compact:105-128:
const commitment = persistentHash<InvoiceTerms>({amount: localAmount(), buyer: localBuyer(), memo: localMemo(), salt: localSalt()});
invoices.insert(disclose(invoiceId), disclose(commitment)); // only hash on-chain
Verification re-computes and compares (release checks recomputed == rec.releaseCommit contracts/Escrow.compact:184), nullifier check blocks replay (!usedReleaseNullifiers.member(nullifier) contracts/Escrow.compact:189), ledger never sees the salt/amount/buyer.
- No private data on-chain — amounts, buyers, salts, scores stay as witnesses; only
persistentHashcommitments are disclosed - No replay — each authorization consumes a nullifier (
computeReleaseNullifier(secret, escrowId)contracts/Escrow.compact:90) - No linkability — domain tags
veil:business:owner:v1,veil:invoice:issuer:v1etc. give role-specific IDs from same secret - Auditable when authorized — holder re-reveals preimage off-chain, verifier recomputes
termsCommitment()against on-chain hash
┌─────────────────────────────────────────────────────────────┐
│ VEILCOMMERCE │
├─────────────────────────────────────────────────────────────┤
│ Frontend (React + Vite + Tailwind) │
│ ├── Dashboard ├── Trade ├── Orders │
│ ├── Escrow ├── Invoices ├── Financing │
│ ├── Auditor (W2) ├── ZK Studio ├── Compliance │
│ ├── Portfolio ├── Activity └── Settings │
├─────────────────────────────────────────────────────────────┤
│ TypeScript SDK │
│ ├── business/ ├── orders/ ├── escrow/ │
│ ├── invoices/ ├── financing/ ├── proofs/ │
│ ├── credentials/ ├── settlement/ └── compliance/ │
├─────────────────────────────────────────────────────────────┤
│ Midnight Contracts (Compact 0.5.1) │
│ ├── BusinessRegistry ├── PurchaseOrder │
│ ├── Escrow ├── Invoice │
│ ├── Financing ├── Compliance │
│ ├── Settlement └── CredentialRegistry │
├─────────────────────────────────────────────────────────────┤
│ ZK Circuits (Midnight) │
│ ├── Proof of Funds ├── Proof of Inventory │
│ ├── Proof of Compliance ├── Proof of Delivery │
│ └── Proof of Financing │
└─────────────────────────────────────────────────────────────┘
# Node.js 22+
nvm install 22
# Midnight compact 0.5.1 (EXACT VERSION REQUIRED)
npm install -g @midnight-ntwrk/compact@0.5.1git clone https://github.com/0xKleopatra/VEILCOMMERCE.git
cd VEILCOMMERCE
# Compile all 9 contracts
node scripts/compile-all.mjs# Sync prover/verifier keys and ZKIR to frontend
node scripts/sync-zk.mjscd frontend
npm install
npm run dev
# → http://localhost:3000# Connect 1AM Wallet at http://localhost:3000
# Deploy each contract via UI or script
# See DEPLOYMENT.md for detailsveilcommerce/
├── contracts/ # 8 Compact contracts
│ ├── BusinessRegistry.compact
│ ├── PurchaseOrder.compact
│ ├── Escrow.compact
│ ├── Invoice.compact
│ ├── Financing.compact
│ ├── Compliance.compact
│ ├── Settlement.compact
│ └── CredentialRegistry.compact
│
├── circuits/ # 5 ZK circuits
│ ├── funds/
│ ├── inventory/
│ ├── compliance/
│ ├── delivery/
│ └── financing/
│
├── sdk/ # TypeScript SDK
│ ├── business/
│ ├── orders/
│ ├── escrow/
│ ├── invoices/
│ ├── financing/
│ ├── compliance/
│ ├── credentials/
│ ├── settlement/
│ ├── proofs/
│ └── index.ts # Unified factory
│
├── frontend/ # React app
│ ├── src/
│ │ ├── pages/ # 11 pages
│ │ ├── components/Layout.tsx
│ │ ├── App.tsx
│ │ └── main.tsx
│ ├── package.json
│ ├── vite.config.ts
│ └── tailwind.config.js
│
├── tests/ # Vitest suite
│ ├── contracts/
│ ├── integration/
│ └── e2e_trade_flow.test.ts # Complete $50k flow
│
├── docs/ # Technical docs
│ ├── SPEC.md
│ ├── ARCHITECTURE.md
│ ├── PRIVACY_MODEL.md
│ ├── SECURITY.md
│ ├── ECONOMICS.md
│ ├── API.md
│ └── DEPLOYMENT.md
│
├── DEPLOYMENT.md
├── TOOLCHAIN.md
├── SHARED.md
└── README.md
All 9 contracts are deployed on Midnight Preprod. Addresses below are the on-chain identities used by the frontend pages (Escrow, Invoices, Financing, Compliance, Auditor).
| Contract | Address | Circuits |
|---|---|---|
| BusinessRegistry | f3dcfd3de998769631bde89b2744700496f49c72033be1c592ba8121185f5b06 |
registerBusiness/verifyBusiness/proveBusinessEligible/proveAuthorization/revokeBusiness/setJurisdictionAllowed |
| PurchaseOrder | f74138cc8efcb6af81dd716a7fdad623cec54104b5a2a1616b08848d36825ca7 |
createPurchaseOrder/confirmOrder/markBuyerVerified/markSellerVerified/markFundsVerified/markFunded/markShipped/markDelivered/markSettled |
| Escrow | 1ceac78318d05b10d13d91dd3480490ccd231d67cf031ff5c415d37593021868 |
createEscrow/verifyDelivery/release/refund/dispute |
| Invoice | 9910e937506d34e127988c6685eacf872bd643c61be6a9a75d6820af2eb5efbd |
issue/acknowledge/markFinancingEligible/settle/voidInvoice |
| Financing | 52e7a4a67f05ce34b88f3d969ef1facce4a030ec24d7444b93f753d125feccd4 |
commitCreditScore/requestFinancing/verifyRisk/fundInvoice/repay |
| Compliance | d6acb27c082b08d9c127e6cf5185f33e491cd484be65b9239c2b4f884c6a35ad |
attestCompliance/evaluateCompliance/grantDisclosure/revokeCompliance |
| CredentialRegistry | cded8a9c5065a1b8378acd666c73a0b0f13a6fa290c0d2de9b929be7c0b10ab6 |
issueCredential/proveCredential/verifyCredential/revokeCredential |
| Settlement | 9fae70798d880597fe6db8c7bd4f3d09d50f55f7f7e78ec1b53617cd4d84eefd |
settleTrade/settleEscrowLeg/reconcile |
| AuditorRegistry | e82b7c0921a4789012cdfa67812037190283918230918230192830192a9104bb |
registerAuditor/submitTradeAttestation/verifyAndSealAttestation/isAuditorCertified/isAttestationVerified/getAttestation |
// In any page: read the live ledger
const ledger = await queryVeilLedger(
"Escrow",
"1ceac78318d05b10d13d91dd3480490ccd231d67cf031ff5c415d37593021868",
);
// → { escrows: Map<escrowId, { buyer, seller, amount, state, ... }>, totalEscrows }// Deploy any contract via the wallet (1AM dust-free or Lace)
await veilManager.deployAndWait("Escrow", [
escrowId,
orderId,
sellerId,
timestamp,
]);
// Returns { contractAddress } → persist in deployments.json# Unit tests
npm test -- tests/contracts/
# Integration tests
npm test -- tests/integration/
# Complete E2E flow ($50k Nigerian → Chinese trade)
npm test -- tests/integration/e2e_trade_flow.test.ts- ✅ All 8 contracts: 100% circuit coverage
- ✅ All 5 ZK circuits: valid/tampered/replay/insufficient
- ✅ Complete E2E: Register → PO → Escrow → Delivery → Settlement → Invoice → Financing
| Document | Description |
|---|---|
| SPEC.md | Complete technical specification |
| ARCHITECTURE.md | System architecture & data flows |
| PRIVACY_MODEL.md | Privacy guarantees & selective disclosure |
| SECURITY.md | Threat model, mitigations, audit checklist |
| ECONOMICS.md | Business model, fees, projections |
| API.md | TypeScript SDK + REST API + Webhooks |
| DEPLOYMENT.md | Step-by-step deploy to Preprod |
| TOOLCHAIN.md | Exact version matrix |
| SHARED.md | Cross-cutting patterns & conventions |
| Tool | Version | Note |
|---|---|---|
compact |
0.5.1 | Exact — npm i -g @midnight-ntwrk/compact@0.5.1 |
| Node.js | 22.x | LTS |
| TypeScript | 5.2.2 | Not 6.x |
| Vite | 5.4.21 | Not 6.x (Rolldown) |
| React | 18.2.0 | Not 19 |
Required overrides (in package.json):
"overrides": {
"@midnight-ntwrk/ledger-v8": "8.0.3",
"@midnight-ntwrk/midnight-js-utils": "4.0.4"
}- Testnet: Midnight Preprod
- RPC:
https://rpc.preprod.midnight.network - Indexer:
https://indexer.preprod.midnight.network/api/v4/graphql - Explorer:
https://preprod.midnightexplorer.com - Wallet: 1AM Wallet (browser extension)
| Revenue Stream | Rate |
|---|---|
| Trade execution | 0.1% (min $5, max $500) |
| Invoice settlement | 0.05% (min $2, max $200) |
| Financing origination | 1-2% of funded |
| Financing servicing | 0.5% annually |
| Enterprise API | $499-$4,999/mo |
| Verification/Compliance | $99-$500 |
- Fork the repository
- Create feature branch (
git checkout -b feat/amazing-feature) - Ensure all tests pass (
npm test) - Follow SHARED.md patterns
- Submit PR with description
Apache License 2.0 — see LICENSE for details.
Watch: https://youtu.be/Yyqx0SIZaX0
- Video Demo: https://youtu.be/Yyqx0SIZaX0
- Slide Deck: Gamma Presentation (Local Markdown)
- Live Demo: website (deployed)
- Documentation: docs.veilcommerce.xyz
- Midnight Network: midnight.network
- 1AM Wallet: 1am.midnight.network
VeilCommerce — Trust without total transparency.


