Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
node_modules/
**/node_modules/

# Logs
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*

# Environment Variables
.env
.env.local
.env.development.local
.env.test.local
.env.production.local

# Build artifacts
dist/
build/
out/
artifacts/
cache/

# Editor & OS specific files
.DS_Store
Thumbs.db
.idea/
.vscode/
*.swp
1 change: 1 addition & 0 deletions artifacts/build-info/417d3dbc8db15915c9bd7194504cd3bf.json

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions artifacts/contracts/Lock.sol/Lock.dbg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"_format": "hh-sol-dbg-1",
"buildInfo": "..\\..\\build-info\\417d3dbc8db15915c9bd7194504cd3bf.json"
}
74 changes: 74 additions & 0 deletions artifacts/contracts/Lock.sol/Lock.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
{
"_format": "hh-sol-artifact-1",
"contractName": "Lock",
"sourceName": "contracts/Lock.sol",
"abi": [
{
"inputs": [
{
"internalType": "uint256",
"name": "_unlockTime",
"type": "uint256"
}
],
"stateMutability": "payable",
"type": "constructor"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "uint256",
"name": "amount",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint256",
"name": "when",
"type": "uint256"
}
],
"name": "Withdrawal",
"type": "event"
},
{
"inputs": [],
"name": "owner",
"outputs": [
{
"internalType": "address payable",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "unlockTime",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "withdraw",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
}
],
"bytecode": "0x60806040526040516105d83803806105d8833981810160405281019061002591906100f0565b804210610067576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161005e906101a0565b60405180910390fd5b8060008190555033600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550506101c0565b600080fd5b6000819050919050565b6100cd816100ba565b81146100d857600080fd5b50565b6000815190506100ea816100c4565b92915050565b600060208284031215610106576101056100b5565b5b6000610114848285016100db565b91505092915050565b600082825260208201905092915050565b7f556e6c6f636b2074696d652073686f756c6420626520696e207468652066757460008201527f7572650000000000000000000000000000000000000000000000000000000000602082015250565b600061018a60238361011d565b91506101958261012e565b604082019050919050565b600060208201905081810360008301526101b98161017d565b9050919050565b610409806101cf6000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c8063251c1aa3146100465780633ccfd60b146100645780638da5cb5b1461006e575b600080fd5b61004e61008c565b60405161005b919061024a565b60405180910390f35b61006c610092565b005b61007661020b565b60405161008391906102a6565b60405180910390f35b60005481565b6000544210156100d7576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016100ce9061031e565b60405180910390fd5b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610167576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161015e9061038a565b60405180910390fd5b7fbf2ed60bd5b5965d685680c01195c9514e4382e28e3a5a2d2d5244bf59411b9347426040516101989291906103aa565b60405180910390a1600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166108fc479081150290604051600060405180830381858888f19350505050158015610208573d6000803e3d6000fd5b50565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6000819050919050565b61024481610231565b82525050565b600060208201905061025f600083018461023b565b92915050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b600061029082610265565b9050919050565b6102a081610285565b82525050565b60006020820190506102bb6000830184610297565b92915050565b600082825260208201905092915050565b7f596f752063616e27742077697468647261772079657400000000000000000000600082015250565b60006103086016836102c1565b9150610313826102d2565b602082019050919050565b60006020820190508181036000830152610337816102fb565b9050919050565b7f596f75206172656e277420746865206f776e6572000000000000000000000000600082015250565b60006103746014836102c1565b915061037f8261033e565b602082019050919050565b600060208201905081810360008301526103a381610367565b9050919050565b60006040820190506103bf600083018561023b565b6103cc602083018461023b565b939250505056fea26469706673582212202d2006ef26cbefcc4deab66c32f5ff5efb638f080c7490b6633879942caf232764736f6c634300081c0033",
"deployedBytecode": "0x608060405234801561001057600080fd5b50600436106100415760003560e01c8063251c1aa3146100465780633ccfd60b146100645780638da5cb5b1461006e575b600080fd5b61004e61008c565b60405161005b919061024a565b60405180910390f35b61006c610092565b005b61007661020b565b60405161008391906102a6565b60405180910390f35b60005481565b6000544210156100d7576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016100ce9061031e565b60405180910390fd5b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610167576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161015e9061038a565b60405180910390fd5b7fbf2ed60bd5b5965d685680c01195c9514e4382e28e3a5a2d2d5244bf59411b9347426040516101989291906103aa565b60405180910390a1600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166108fc479081150290604051600060405180830381858888f19350505050158015610208573d6000803e3d6000fd5b50565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6000819050919050565b61024481610231565b82525050565b600060208201905061025f600083018461023b565b92915050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b600061029082610265565b9050919050565b6102a081610285565b82525050565b60006020820190506102bb6000830184610297565b92915050565b600082825260208201905092915050565b7f596f752063616e27742077697468647261772079657400000000000000000000600082015250565b60006103086016836102c1565b9150610313826102d2565b602082019050919050565b60006020820190508181036000830152610337816102fb565b9050919050565b7f596f75206172656e277420746865206f776e6572000000000000000000000000600082015250565b60006103746014836102c1565b915061037f8261033e565b602082019050919050565b600060208201905081810360008301526103a381610367565b9050919050565b60006040820190506103bf600083018561023b565b6103cc602083018461023b565b939250505056fea26469706673582212202d2006ef26cbefcc4deab66c32f5ff5efb638f080c7490b6633879942caf232764736f6c634300081c0033",
"linkReferences": {},
"deployedLinkReferences": {}
}
4 changes: 4 additions & 0 deletions artifacts/contracts/testament.sol/Testament.dbg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"_format": "hh-sol-dbg-1",
"buildInfo": "..\\..\\build-info\\92444c75696ebbe6a5754629414e62ee.json"
}
254 changes: 254 additions & 0 deletions artifacts/contracts/testament.sol/Testament.json

Large diffs are not rendered by default.

77 changes: 77 additions & 0 deletions cache/solidity-files-cache.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
{
"_format": "hh-sol-cache-2",
"files": {
"C:\\Users\\Admin\\Programiranje\\ZkInheritance\\contracts\\Lock.sol": {
"lastModificationDate": 1739110046782,
"contentHash": "7eee587c347fe6b1de50c96688cb9477",
"sourceName": "contracts/Lock.sol",
"solcConfig": {
"version": "0.8.28",
"settings": {
"evmVersion": "paris",
"optimizer": {
"enabled": false,
"runs": 200
},
"outputSelection": {
"*": {
"*": [
"abi",
"evm.bytecode",
"evm.deployedBytecode",
"evm.methodIdentifiers",
"metadata"
],
"": [
"ast"
]
}
}
}
},
"imports": [],
"versionPragmas": [
"^0.8.28"
],
"artifacts": [
"Lock"
]
},
"C:\\Users\\Admin\\Programiranje\\ZkInheritance\\contracts\\testament.sol": {
"lastModificationDate": 1739112477069,
"contentHash": "ec864fb0d7c84a0b5ce46dcd13dcef5c",
"sourceName": "contracts/testament.sol",
"solcConfig": {
"version": "0.8.28",
"settings": {
"evmVersion": "paris",
"optimizer": {
"enabled": false,
"runs": 200
},
"outputSelection": {
"*": {
"*": [
"abi",
"evm.bytecode",
"evm.deployedBytecode",
"evm.methodIdentifiers",
"metadata"
],
"": [
"ast"
]
}
}
}
},
"imports": [],
"versionPragmas": [
"^0.8.20"
],
"artifacts": [
"Testament"
]
}
}
}
34 changes: 34 additions & 0 deletions contracts/Lock.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.28;

// Uncomment this line to use console.log
// import "hardhat/console.sol";

contract Lock {
uint public unlockTime;
address payable public owner;

event Withdrawal(uint amount, uint when);

constructor(uint _unlockTime) payable {
require(
block.timestamp < _unlockTime,
"Unlock time should be in the future"
);

unlockTime = _unlockTime;
owner = payable(msg.sender);
}

function withdraw() public {
// Uncomment this line, and the import of "hardhat/console.sol", to print a log in your terminal
// console.log("Unlock time is %o and block timestamp is %o", unlockTime, block.timestamp);

require(block.timestamp >= unlockTime, "You can't withdraw yet");
require(msg.sender == owner, "You aren't the owner");

emit Withdrawal(address(this).balance, block.timestamp);

owner.transfer(address(this).balance);
}
}
80 changes: 80 additions & 0 deletions contracts/testament.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

contract Testament {
struct Heir {
address heirAddress;
uint256 percentage;
string documentHash;
}

struct TestamentData {
address owner;
address lawyer;
bool isActive;
Heir[] heirs;
}

mapping(uint256 => TestamentData) public testaments;
uint256 public testamentCount;

event TestamentCreated(uint256 indexed testamentId, address owner, address lawyer);
event TestamentActivated(uint256 indexed testamentId);
event InheritanceClaimed(uint256 indexed testamentId, address heir, uint256 amount);

constructor() {}

function createTestament(address _lawyer) external returns (uint256) {
testamentCount++;
TestamentData storage newTestament = testaments[testamentCount];
newTestament.owner = msg.sender;
newTestament.lawyer = _lawyer;
newTestament.isActive = false;

emit TestamentCreated(testamentCount, msg.sender, _lawyer);
return testamentCount;
}

function addHeir(uint256 _testamentId, address _heir, uint256 _percentage, string memory _documentHash) external {
require(msg.sender == testaments[_testamentId].owner, "Only owner can add heirs");
testaments[_testamentId].heirs.push(Heir(_heir, _percentage, _documentHash));
}

function getHeirs(uint256 _testamentId) external view returns (Heir[] memory) {
return testaments[_testamentId].heirs;
}


function activateTestament(uint256 _testamentId) external {
require(msg.sender == testaments[_testamentId].lawyer, "Only assigned lawyer can activate the testament");
testaments[_testamentId].isActive = true;
emit TestamentActivated(_testamentId);
}

// omogućava nasledniku da vidi šta nasledjuje pre aktivacije
function viewInheritance(uint256 _testamentId) external view returns (uint256, string memory) {
for (uint256 i = 0; i < testaments[_testamentId].heirs.length; i++) {
if (testaments[_testamentId].heirs[i].heirAddress == msg.sender) {
return (
testaments[_testamentId].heirs[i].percentage,
testaments[_testamentId].heirs[i].documentHash
);
}
}
revert("You are not listed as an heir");
}

// naslednik može povući sredstva tek nakon aktivacije testamenta
function claimInheritance(uint256 _testamentId) external {
require(testaments[_testamentId].isActive, "Testament is not active");

for (uint256 i = 0; i < testaments[_testamentId].heirs.length; i++) {
if (testaments[_testamentId].heirs[i].heirAddress == msg.sender) {
uint256 amount = testaments[_testamentId].heirs[i].percentage;
emit InheritanceClaimed(_testamentId, msg.sender, amount);
return;
}
}
revert("You are not listed as an heir");
}
}
6 changes: 6 additions & 0 deletions hardhat.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
require("@nomicfoundation/hardhat-toolbox");

/** @type import('hardhat/config').HardhatUserConfig */
module.exports = {
solidity: "0.8.28",
};
18 changes: 18 additions & 0 deletions ignition/modules/Lock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// This setup uses Hardhat Ignition to manage smart contract deployments.
// Learn more about it at https://hardhat.org/ignition

const { buildModule } = require("@nomicfoundation/hardhat-ignition/modules");

const JAN_1ST_2030 = 1893456000;
const ONE_GWEI = 1_000_000_000n;

module.exports = buildModule("LockModule", (m) => {
const unlockTime = m.getParameter("unlockTime", JAN_1ST_2030);
const lockedAmount = m.getParameter("lockedAmount", ONE_GWEI);

const lock = m.contract("Lock", [unlockTime], {
value: lockedAmount,
});

return { lock };
});
13 changes: 0 additions & 13 deletions node_modules/.package-lock.json

This file was deleted.

Loading