TimeLockedVault reference
Use this reference to inspect data structures, state variables, primary functions, and emitted events. Copy the snippets into audits or internal reviews.
Vault structure
struct Vault {
string ipfsHash; // Encrypted file location
string encryptedKey; // AES 256 key, sealed
uint256 unlockTime; // Unix time for release
address creator; // Creator address
bool isVoided; // True when destroyed
uint256 createdAt; // Block time of creation
}Each vault is addressed by a numeric id. The mapping is public so anyone can verify inputs against contract state.
State variables
mapping(uint256 => Vault)
vaults
Stores every vault by identifier. Public for verification.
uint256
vaultCounter
Monotonic id generator for new vaults.
address
owner
Contract owner allowed to run administrative routines such as pausing or upgrades if configured.
Primary functions
createVault
function createVault(
string memory ipfsHash,
string memory encryptedKey,
uint256 unlockTime
) public returns (uint256)- Purpose: Create a new vault and store inputs on chain.
- Parameters: ipfsHash (CID), encryptedKey (AES 256 key), unlockTime (Unix time).
- Returns: Numeric vault id.
- Emits: VaultCreated with id, creator, and unlock time.
unlockVault
function unlockVault(uint256 vaultId)
public
view
returns (string memory)- Purpose: Return the encrypted key when the unlock time has passed.
- Reverts: If the vault is missing, not yet ready, or has been voided.
- Read only: No gas heavy state changes; callers can check readiness without extra cost.
voidVault
function voidVault(uint256 vaultId)
public
onlyCreator- Purpose: Destroy a vault before release when policy demands invalidation.
- Access: Only the creator can void. Sets isVoided to true.
- Emits: VaultVoided with id and creator.
Error codes
E01
VAULT_LOCKED
Unlock time has not arrived.
E02
VAULT_NOT_FOUND
Requested vault id does not exist.
E03
VAULT_VOIDED
Vault was destroyed and cannot return a key.
E04
UNAUTHORIZED
Caller lacks permission for the action.
Events
event VaultCreated(
uint256 indexed vaultId,
address indexed creator,
uint256 unlockTime
);event VaultUnlocked(
uint256 indexed vaultId,
address indexed caller
);event VaultVoided(
uint256 indexed vaultId,
address indexed creator
);