Hi @DR.Ecovery! Following up on this after chatting with our team
To give you a concrete path forward for the 42 CFR Part 2 “status anonymity” requirement, we recommend a two-layered architecture:
1. Anonymous Check-ins (The Membership Proof Pattern)
To satisfy the rule that “even being a patient” is protected status, you can use a Membership Proof + Nullifier. This proves “I am someone on the clinic’s list” without revealing which leaf in the tree you are.
Example of how to implement this in Compact:
// 1. A private tree of all authorized patient commitments
ledger patientTree: HistoricMerkleTree<32, Bytes<32>>;
// 2. Prevent double-check-ins using a daily Nullifier
ledger usedNullifiers: Set<Bytes<32>>;
witness patientPath(): MerkleTreePath<32, Bytes<32>>;
witness patientSecret(): Bytes<32>;
export circuit checkIn(currentDate: Bytes<32>): [] {
const path = patientPath();
const sk = patientSecret();
// Prove the user is in the patient tree without revealing their identity
assert(patientTree.checkRoot(merkleTreePathRoot<32, Bytes<32>>(path)));
assert(persistentHash<Bytes<32>>(sk) == path.leaf);
// Use a nullifier (Secret + Date) to prevent identity tracking
const nullifier = persistentHash<Vector<2, Bytes<32>>>([sk, currentDate]);
assert(!usedNullifiers.member(nullifier), "Already checked in today");
usedNullifiers.insert(nullifier);
}
2. Confidential Record Storage (Off-chain Pattern)
For the actual medical records (treatment notes), you shouldn’t store them on-chain. Instead, use a pattern of Client-side Encryption + IPFS.
The Storage Pattern:
struct DocumentRecord {
contentHash: Bytes<32>, // Hash of the encrypted file for integrity
storageCid: Opaque<"string">, // The IPFS/Arweave CID
ownerCommitment: Bytes<32>, // Commitment of the patient who owns it
isActive: Boolean
}
export ledger records: Map<Bytes<32>, DocumentRecord>;
Workflow:
- Encrypt Locally: Use AES-256-GCM to encrypt the records on the provider’s device.
- IPFS: Upload the encrypted blob to IPFS.
- Audit Trail: Store only the CID and the hash on Midnight. This gives you a mathematical audit trail without ever exposing the patient’s data or status to the public ledger.
Reference Resources
We have a community-led reference project called midnight-doc-manager that demonstrates this exact encryption-to-IPFS flow. It’s an excellent starting point for how to handle large, sensitive files while keeping the verification on Midnight.
You can also find our official, maintained examples here:
midnightntwrk repositories · GitHub
Does this technical architecture align with your compliance requirements? We’d love to hear how your implementation goes!