Overview
TheMedicalRecord is a private record structure that stores encrypted patient health data on the Aleo blockchain. Only the patient (record owner) can decrypt and read the contents.
Fields
The patient’s Aleo address. This field establishes automatic record ownership - only the owner can access and decrypt the medical data.
Unique identifier for this medical record. Generated as a hash of the patient address, data hash, and client-provided nonce using BHP256:This deterministic generation allows client-side computation before record creation.
Hash of the original encrypted data for integrity verification. Clients should store this hash to verify data hasn’t been tampered with when reconstructing the medical record.
First segment of encrypted medical data. Each field element can store approximately 31 bytes of encrypted data (~253 bits).
Second segment of encrypted medical data.
Third segment of encrypted medical data.
Fourth segment of encrypted medical data.
Fifth segment of encrypted medical data.
Sixth segment of encrypted medical data.
Seventh segment of encrypted medical data.
Eighth segment of encrypted medical data.
Ninth segment of encrypted medical data.
Tenth segment of encrypted medical data.
Eleventh segment of encrypted medical data.
Twelfth segment of encrypted medical data.
Category of the medical record. Valid values are 1-10. See Record Types for the complete enumeration.The contract validates this field:
assert(record_type >= 1u8 && record_type <= 10u8)Block height when the record was created. This field is set to
0u32 in the record itself - the actual creation block height is stored in the public RecordMetadata mapping if the record is made discoverable.Schema version for future upgradability. Currently set to
1u8 for all records. This allows the contract to support format changes in future versions while maintaining backward compatibility.Storage Capacity
The MedicalRecord structure provides approximately 372 bytes of encrypted data storage:- 12 field elements × 31 bytes per field = ~372 bytes total capacity
- Each field can store ~253 bits (31 bytes) of data
- Data must be encrypted client-side before storage
- For larger medical records, implement chunking across multiple MedicalRecord instances
The contract architecture comment mentions “~126 bytes encrypted capacity” referring to the original 4-field design, but the current implementation uses 12 fields, providing approximately 372 bytes of storage.
Privacy Model
MedicalRecord is a private record, meaning:- Only the owner (patient) can view the record contents
- The record is NOT stored in public blockchain state
- Access is controlled by Aleo’s record ownership model
- Even with a valid access token, doctors cannot decrypt the data without the patient sharing the encrypted record off-chain
Creating a Medical Record
Medical records are created using thecreate_record transition:
Related Structures
- AccessGrant - Temporary access permissions for healthcare providers
- Record Types - Medical record categories and enumeration
- RecordMetadata - Public indexing structure (optional)
Security Considerations
Data Integrity: Always verify the
data_hash matches your decrypted data to ensure integrity when reconstructing medical records.Unique Record IDs: The combination of patient address, data hash, and nonce ensures globally unique record IDs. Clients can compute the record_id before creation using the
compute_record_id helper function.