Skip to content

Usage Examples

This page provides practical examples for using the Zaphenath contract in real scenarios, focusing on core operations such as key creation, access control, and timeout behavior.


๐Ÿงช Create a Key

vm.prank(rachel);
zaph.createKey("0xabc123", bytes("Top Secret"), 3 days, true);

Rachel creates a key that will become public in 3 days unless she pings.


๐Ÿ”’ Reader Can't Read Before Timeout

vm.prank(rachel);
zaph.setCustodian("0xabc123", rachel, jacob, Role.Reader);

vm.prank(jacob);
vm.expectRevert("Insufficient role");
zaph.readKey("0xabc123", rachel);

Jacob is a Reader, but can't read before the timeout expires.


โŒ› Read After Timeout

vm.warp(block.timestamp + 4 days);

vm.prank(jacob);
bytes memory data = zaph.readKey("0xabc123", rachel);

After the timeout, Jacob can read the key.


๐Ÿ” Custodian Pings

vm.prank(rachel);
zaph.setCustodian("0xabc123", rachel, jacob, Role.Writer, true);

vm.prank(jacob);
zaph.ping("0xabc123", rachel);

Jacob keeps the data private by resetting the timeout.


๐Ÿ—‘ Delete Key

vm.prank(rachel);
zaph.deleteKey("0xabc123", rachel);

Key is removed permanently.


โžก๏ธ Next: Test Coverage