secure-transac-contracts 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/build/contracts/AccessControl.json +4579 -0
  2. package/build/contracts/Context.json +356 -0
  3. package/build/contracts/CreditSystem.json +6037 -0
  4. package/build/contracts/ECDSA.json +4734 -0
  5. package/build/contracts/EIP712.json +3021 -0
  6. package/build/contracts/ERC165.json +352 -0
  7. package/build/contracts/ERC20.json +6816 -0
  8. package/build/contracts/ERC20Permit.json +2658 -0
  9. package/build/contracts/ERC721.json +12779 -0
  10. package/build/contracts/ERC721Utils.json +1058 -0
  11. package/build/contracts/Groth16Verifier.json +6298 -0
  12. package/build/contracts/Guardian.json +1116 -0
  13. package/build/contracts/IERC1155Errors.json +1687 -0
  14. package/build/contracts/IERC165.json +197 -0
  15. package/build/contracts/IERC20.json +1162 -0
  16. package/build/contracts/IERC20Errors.json +1662 -0
  17. package/build/contracts/IERC20Metadata.json +574 -0
  18. package/build/contracts/IERC20Permit.json +546 -0
  19. package/build/contracts/IERC5267.json +392 -0
  20. package/build/contracts/IERC721.json +1729 -0
  21. package/build/contracts/IERC721Errors.json +1694 -0
  22. package/build/contracts/IERC721Metadata.json +728 -0
  23. package/build/contracts/IERC721Receiver.json +296 -0
  24. package/build/contracts/IGuardian.json +215 -0
  25. package/build/contracts/ITrustRegistry.json +6767 -0
  26. package/build/contracts/IdentityVault.json +11584 -0
  27. package/build/contracts/Math.json +23115 -0
  28. package/build/contracts/MessageHashUtils.json +1668 -0
  29. package/build/contracts/Nonces.json +865 -0
  30. package/build/contracts/Ownable.json +1859 -0
  31. package/build/contracts/Panic.json +798 -0
  32. package/build/contracts/ReportingSystem.json +2787 -0
  33. package/build/contracts/SafeCast.json +21592 -0
  34. package/build/contracts/ScoringSystem.json +11245 -0
  35. package/build/contracts/SecureTransacSBT.json +18823 -0
  36. package/build/contracts/SecureTransacToken.json +19225 -0
  37. package/build/contracts/SecureVault.json +12890 -0
  38. package/build/contracts/ShortStrings.json +2852 -0
  39. package/build/contracts/SignedMath.json +1915 -0
  40. package/build/contracts/StorageSlot.json +1773 -0
  41. package/build/contracts/Strings.json +19001 -0
  42. package/build/contracts/TransactionLogger.json +5325 -0
  43. package/build/contracts/TrustDAO.json +23850 -0
  44. package/build/contracts/TrustRegistry.json +10948 -0
  45. package/build/contracts/VerificationRegistry.json +12811 -0
  46. package/build/contracts/ZKIdentityVerifier.json +13979 -0
  47. package/contracts/AccessControl.sol +34 -0
  48. package/contracts/CreditSystem.sol +48 -0
  49. package/contracts/Guardian.sol +33 -0
  50. package/contracts/IGuardian.sol +7 -0
  51. package/contracts/IdentityVault.sol +57 -0
  52. package/contracts/ReportingSystem.sol +14 -0
  53. package/contracts/ScoringSystem.sol +71 -0
  54. package/contracts/SecureTransacSBT.sol +72 -0
  55. package/contracts/SecureTransacToken.sol +20 -0
  56. package/contracts/SecureVault.sol +24 -0
  57. package/contracts/TransactionLogger.sol +12 -0
  58. package/contracts/TrustDAO.sol +158 -0
  59. package/contracts/TrustRegistry.sol +23 -0
  60. package/contracts/VerificationRegistry.sol +51 -0
  61. package/contracts/ZKIdentityVerifier.sol +38 -0
  62. package/contracts/ZKScoreVerifier.sol +175 -0
  63. package/package.json +32 -0
@@ -0,0 +1,34 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.0;
3
+
4
+ import "@openzeppelin/contracts/access/Ownable.sol";
5
+
6
+ contract AccessControl is Ownable {
7
+ enum AuthorityTier { NONE, STANDARD, INSTITUTIONAL, DIAMOND }
8
+
9
+ mapping(address => bool) public isAuthorizedReporter;
10
+ mapping(address => AuthorityTier) public reporterTier;
11
+
12
+ event ReporterStatusChanged(address indexed reporter, bool status, AuthorityTier tier);
13
+
14
+ constructor() Ownable(msg.sender) {
15
+ // Owner is the default Diamond reporter
16
+ isAuthorizedReporter[msg.sender] = true;
17
+ reporterTier[msg.sender] = AuthorityTier.DIAMOND;
18
+ }
19
+
20
+ modifier onlyReporter() {
21
+ require(isAuthorizedReporter[msg.sender], "Not an authorized reporter");
22
+ _;
23
+ }
24
+
25
+ function setReporterStatus(
26
+ address reporter,
27
+ bool status,
28
+ AuthorityTier tier
29
+ ) external onlyOwner {
30
+ isAuthorizedReporter[reporter] = status;
31
+ reporterTier[reporter] = status ? tier : AuthorityTier.NONE;
32
+ emit ReporterStatusChanged(reporter, status, tier);
33
+ }
34
+ }
@@ -0,0 +1,48 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.0;
3
+
4
+ import "./AccessControl.sol";
5
+
6
+ contract CreditSystem is AccessControl { // Inherit AccessControl to share base with others
7
+ mapping(address => uint256) public credits;
8
+ uint256 public constant VIEW_COST = 0.01 ether; // Cost to view a private score (in wei/credits)
9
+
10
+ // SCALE: 1 ETH = 1 Credit (for simplicity in this demo, using wei values directly)
11
+ // In a real app, you might want a different exchange rate. Here 1 wei deposited = 1 unit credit.
12
+
13
+ event CreditsDeposited(address indexed user, uint256 amount);
14
+ event CreditsDeducted(address indexed user, uint256 amount);
15
+
16
+ /**
17
+ * @dev Deposit ETH to get credits.
18
+ * 1 wei = 1 credit unit.
19
+ */
20
+ function deposit() public payable {
21
+ require(msg.value > 0, "Must deposit non-zero amount");
22
+ credits[msg.sender] += msg.value;
23
+ emit CreditsDeposited(msg.sender, msg.value);
24
+ }
25
+
26
+ /**
27
+ * @dev Returns the credit balance of the caller.
28
+ */
29
+ function myCredits() public view returns (uint256) {
30
+ return credits[msg.sender];
31
+ }
32
+
33
+ /**
34
+ * @dev Internal function to deduct credits.
35
+ * Throws if insufficient balance.
36
+ */
37
+ function _deductCredits(address user, uint256 amount) internal {
38
+ require(credits[user] >= amount, "Insufficient credits");
39
+ credits[user] -= amount;
40
+ emit CreditsDeducted(user, amount);
41
+ }
42
+
43
+ // Allow admin to withdraw funds accumulated in the contract
44
+ function withdraw() public onlyOwner {
45
+ uint256 balance = address(this).balance;
46
+ payable(owner()).transfer(balance);
47
+ }
48
+ }
@@ -0,0 +1,33 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.0;
3
+
4
+ import "./TrustRegistry.sol";
5
+
6
+ /**
7
+ * @title Guardian
8
+ * @dev Base contract to provide trust-score based access control.
9
+ */
10
+ abstract contract Guardian {
11
+ TrustRegistry public immutable registry;
12
+ uint256 public minRequiredScore;
13
+
14
+ error InsufficientTrustScore(address user, uint256 score, uint256 required);
15
+ error AddressBlacklisted(address user);
16
+
17
+ constructor(address _registry, uint256 _minScore) {
18
+ registry = TrustRegistry(_registry);
19
+ minRequiredScore = _minScore;
20
+ }
21
+
22
+ modifier onlyTrusted() {
23
+ uint256 userScore = registry.getScore(msg.sender);
24
+
25
+ require(!registry.isBlacklisted(msg.sender), "Address blacklisted");
26
+ require(userScore >= minRequiredScore, "Insufficient trust score");
27
+ _;
28
+ }
29
+
30
+ function updateMinScore(uint256 _newMinScore) internal {
31
+ minRequiredScore = _newMinScore;
32
+ }
33
+ }
@@ -0,0 +1,7 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.0;
3
+
4
+ interface IGuardian {
5
+ function registry() external view returns (address);
6
+ function minRequiredScore() external view returns (uint256);
7
+ }
@@ -0,0 +1,57 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.0;
3
+
4
+ import "./Guardian.sol";
5
+
6
+ /**
7
+ * @title IdentityVault
8
+ * @dev Stores encrypted user data (IPFS hashes) and manages access reveal for authorities.
9
+ */
10
+ contract IdentityVault is Guardian {
11
+ struct EncryptedData {
12
+ string ipfsHash;
13
+ uint256 timestamp;
14
+ bool exists;
15
+ }
16
+
17
+ mapping(address => EncryptedData) private userToData;
18
+ mapping(address => bool) public isAuthorizedAuthority;
19
+
20
+ event DataStored(address indexed user, string ipfsHash);
21
+ event DataRequested(address indexed user, address indexed authority);
22
+ event AuthorityStatusChanged(address indexed authority, bool status);
23
+
24
+ error NotAuthorizedAuthority(address authority);
25
+ error DataNotFound(address user);
26
+
27
+ constructor(address _registry) Guardian(_registry, 600) {
28
+ // Owner/Registry owner can set authorities
29
+ }
30
+
31
+ function setAuthorityStatus(address authority, bool status) external {
32
+ // Simple logic: Only registry owner can set authorities
33
+ require(msg.sender == registry.owner(), "Only registry owner can set authorities");
34
+ isAuthorizedAuthority[authority] = status;
35
+ emit AuthorityStatusChanged(authority, status);
36
+ }
37
+
38
+ // Store user's own encrypted identity data - no trust score required for own data
39
+ function storeData(string calldata _ipfsHash) external {
40
+ userToData[msg.sender] = EncryptedData({
41
+ ipfsHash: _ipfsHash,
42
+ timestamp: block.timestamp,
43
+ exists: true
44
+ });
45
+ emit DataStored(msg.sender, _ipfsHash);
46
+ }
47
+
48
+ function requestData(address _user) external view returns (string memory) {
49
+ if (!isAuthorizedAuthority[msg.sender]) {
50
+ revert NotAuthorizedAuthority(msg.sender);
51
+ }
52
+ if (!userToData[_user].exists) {
53
+ revert DataNotFound(_user);
54
+ }
55
+ return userToData[_user].ipfsHash;
56
+ }
57
+ }
@@ -0,0 +1,14 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.0;
3
+
4
+ // Reporting does not necessarily need strict access control if meant to be public,
5
+ // but referencing AccessControl for consistency or future restrictions.
6
+ import "./AccessControl.sol";
7
+
8
+ contract ReportingSystem {
9
+ event ReportSubmitted(address indexed reporter, address indexed target, string reason, uint256 timestamp);
10
+
11
+ function submitReport(address target, string calldata reason) external {
12
+ emit ReportSubmitted(msg.sender, target, reason, block.timestamp);
13
+ }
14
+ }
@@ -0,0 +1,71 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.0;
3
+
4
+ import "./AccessControl.sol";
5
+ import "./CreditSystem.sol";
6
+
7
+ contract ScoringSystem is CreditSystem {
8
+ mapping(address => uint256) private scores;
9
+
10
+ uint256 public whitelistThreshold = 800; // 0.8
11
+ uint256 public blacklistThreshold = 200; // 0.2
12
+
13
+ event ScoreUpdated(address indexed user, uint256 newScore);
14
+ event ThresholdUpdated(uint256 whitelistThreshold, uint256 blacklistThreshold);
15
+ event ScoreRevealed(address indexed target, uint256 score, address indexed viewer);
16
+
17
+ function updateScore(address user, uint256 newScore) external onlyReporter {
18
+ require(newScore <= 1000, "Score must be between 0 and 1000");
19
+ scores[user] = newScore;
20
+ emit ScoreUpdated(user, newScore);
21
+ }
22
+
23
+ function setThresholds(
24
+ uint256 _whitelistThreshold,
25
+ uint256 _blacklistThreshold
26
+ ) external onlyOwner {
27
+ require(_whitelistThreshold <= 1000, "Whitelist threshold must be <= 1000");
28
+ require(_blacklistThreshold <= 1000, "Blacklist threshold must be <= 1000");
29
+ require(_whitelistThreshold > _blacklistThreshold, "Whitelist must be > blacklist");
30
+
31
+ whitelistThreshold = _whitelistThreshold;
32
+ blacklistThreshold = _blacklistThreshold;
33
+ emit ThresholdUpdated(_whitelistThreshold, _blacklistThreshold);
34
+ }
35
+
36
+ /**
37
+ * @dev Pay to view a score. Deducts credits from user.
38
+ */
39
+ function accessScore(address target) public returns (uint256) {
40
+ // Admin can view for free (owner)
41
+ if (owner() != _msgSender()) {
42
+ _deductCredits(_msgSender(), VIEW_COST);
43
+ }
44
+
45
+ uint256 score = scores[target];
46
+ if (score == 0) score = 500; // Default
47
+
48
+ emit ScoreRevealed(target, score, _msgSender());
49
+ return score;
50
+ }
51
+
52
+ /**
53
+ * @dev Admin view for free.
54
+ */
55
+ function getScore(address user) external view onlyOwner returns (uint256) {
56
+ uint256 score = scores[user];
57
+ return score == 0 ? 500 : score;
58
+ }
59
+
60
+ function isWhitelisted(address user) public view returns (bool) {
61
+ uint256 score = scores[user];
62
+ if (score == 0) score = 500;
63
+ return score >= whitelistThreshold;
64
+ }
65
+
66
+ function isBlacklisted(address user) public view returns (bool) {
67
+ uint256 score = scores[user];
68
+ if (score == 0) return false;
69
+ return score <= blacklistThreshold;
70
+ }
71
+ }
@@ -0,0 +1,72 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.0;
3
+
4
+ import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
5
+ import "@openzeppelin/contracts/access/Ownable.sol";
6
+
7
+ interface ITrustRegistry {
8
+ function getScore(address user) external view returns (uint256);
9
+ }
10
+
11
+ /**
12
+ * @title SecureTransacSBT
13
+ * @dev Soulbound Token representing a user's reputation.
14
+ * Non-transferable and visually evolves based on TrustRegistry score.
15
+ */
16
+ contract SecureTransacSBT is ERC721, Ownable {
17
+ ITrustRegistry public registry;
18
+
19
+ mapping(address => bool) private _hasMinted;
20
+
21
+ event ReputationCardMinted(address indexed user, uint256 initialScore);
22
+
23
+ constructor(address _registry) ERC721("SecureTransac Reputation Card", "STRC") Ownable(msg.sender) {
24
+ registry = ITrustRegistry(_registry);
25
+ }
26
+
27
+ /**
28
+ * @dev Mint a soulbound card. Can only be done once per address.
29
+ */
30
+ function mint() external {
31
+ require(!_hasMinted[msg.sender], "SBT already minted");
32
+
33
+ uint256 score = registry.getScore(msg.sender);
34
+ _hasMinted[msg.sender] = true;
35
+ _safeMint(msg.sender, uint256(uint160(msg.sender))); // ID is the address representation
36
+
37
+ emit ReputationCardMinted(msg.sender, score);
38
+ }
39
+
40
+ /**
41
+ * @dev Prevent transfers (Soulbound logic)
42
+ */
43
+ function _update(address to, uint256 tokenId, address auth) internal override returns (address) {
44
+ address from = _ownerOf(tokenId);
45
+ if (from != address(0) && to != address(0)) {
46
+ revert("SBT: Transfer not allowed");
47
+ }
48
+ return super._update(to, tokenId, auth);
49
+ }
50
+
51
+ /**
52
+ * @dev Returns the level based on the trust score.
53
+ */
54
+ function getReputationLevel(address user) public view returns (string memory) {
55
+ uint256 score = registry.getScore(user);
56
+ if (score >= 900) return "DIAMOND";
57
+ if (score >= 800) return "PLATINUM";
58
+ if (score >= 600) return "GOLD";
59
+ if (score >= 400) return "SILVER";
60
+ return "BRONZE";
61
+ }
62
+
63
+ function tokenURI(uint256 tokenId) public view override returns (string memory) {
64
+ _requireOwned(tokenId);
65
+ address ownerAddr = address(uint160(tokenId));
66
+ string memory level = getReputationLevel(ownerAddr);
67
+
68
+ // In production, this would return a base64 encoded JSON or IPFS link
69
+ // For the demo, we return a mock dynamic metadata string
70
+ return string(abi.encodePacked("SecureTransac-SBT-Level:", level));
71
+ }
72
+ }
@@ -0,0 +1,20 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.0;
3
+
4
+ import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
5
+ import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Permit.sol";
6
+ import "@openzeppelin/contracts/access/Ownable.sol";
7
+
8
+ /**
9
+ * @title SecureTransacToken ($TRUST)
10
+ * @dev Governance and utility token for the SecureTransac Network.
11
+ */
12
+ contract SecureTransacToken is ERC20, ERC20Permit, Ownable {
13
+ constructor() ERC20("SecureTransac Trust Token", "TRUST") ERC20Permit("SecureTransac") Ownable(msg.sender) {
14
+ _mint(msg.sender, 1000000 * 10 ** decimals()); // 1 Million tokens initially
15
+ }
16
+
17
+ function mint(address to, uint256 amount) public onlyOwner {
18
+ _mint(to, amount);
19
+ }
20
+ }
@@ -0,0 +1,24 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.0;
3
+
4
+ import "./Guardian.sol";
5
+
6
+ /**
7
+ * @title SecureVault
8
+ * @dev Example contract demonstrating SecureTransac protection.
9
+ */
10
+ contract SecureVault is Guardian {
11
+ string public secret;
12
+
13
+ constructor(address _registry) Guardian(_registry, 700) {
14
+ secret = "This is a protected secret!";
15
+ }
16
+
17
+ function setSecret(string calldata _newSecret) external onlyTrusted {
18
+ secret = _newSecret;
19
+ }
20
+
21
+ function getSecret() external view onlyTrusted returns (string memory) {
22
+ return secret;
23
+ }
24
+ }
@@ -0,0 +1,12 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.0;
3
+
4
+ import "./AccessControl.sol";
5
+
6
+ contract TransactionLogger is AccessControl { // Inheriting AccessControl for onlyReporter
7
+ event TransactionLogged(address indexed from, address indexed to, uint256 amount, uint256 timestamp);
8
+
9
+ function recordTransaction(address from, address to, uint256 amount) external onlyReporter {
10
+ emit TransactionLogged(from, to, amount, block.timestamp);
11
+ }
12
+ }
@@ -0,0 +1,158 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.0;
3
+
4
+ import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
5
+ import "@openzeppelin/contracts/access/Ownable.sol";
6
+
7
+ interface ITrustRegistry {
8
+ enum AuthorityTier { NONE, STANDARD, INSTITUTIONAL, DIAMOND }
9
+ function setReporterStatus(address reporter, bool status, AuthorityTier tier) external;
10
+ }
11
+
12
+ /**
13
+ * @title TrustDAO
14
+ * @dev Governance system for SecureTransac.
15
+ * Handles Authority Staking and Parameter Voting.
16
+ */
17
+ contract TrustDAO is Ownable {
18
+ IERC20 public trustToken;
19
+ ITrustRegistry public registry;
20
+
21
+ uint256 public constant MIN_STAKE = 1000 * 10**18; // 1000 $TRUST
22
+ uint256 public constant VOTING_PERIOD = 3 days;
23
+
24
+ struct Proposal {
25
+ uint256 id;
26
+ address proposer;
27
+ string description;
28
+ uint256 forVotes;
29
+ uint256 againstVotes;
30
+ uint256 endTime;
31
+ bool executed;
32
+ mapping(address => bool) hasVoted;
33
+ }
34
+
35
+ mapping(uint256 => Proposal) public proposals;
36
+ uint256 public nextProposalId;
37
+
38
+ mapping(address => uint256) public stakes;
39
+ mapping(address => bool) public isStakedReporter;
40
+
41
+ event Staked(address indexed user, uint256 amount);
42
+ event Unstaked(address indexed user, uint256 amount);
43
+ mapping(address => uint256) public claimableRewards;
44
+ uint256 public totalDistributedRewards;
45
+
46
+ event RewardsClaimed(address indexed user, uint256 amount);
47
+ event RewardsDistributed(uint256 amount);
48
+ event ProposalCreated(uint256 indexed id, string description);
49
+ event Voted(uint256 indexed id, address indexed voter, bool support, uint256 weight);
50
+
51
+ constructor(address _token, address _registry) Ownable(msg.sender) {
52
+ trustToken = IERC20(_token);
53
+ registry = ITrustRegistry(_registry);
54
+ }
55
+
56
+ /**
57
+ * @dev Distribute protocol fees (in $TRUST) to all staked authorities.
58
+ * In production, this would be auto-triggered by the credit system conversion.
59
+ */
60
+ function distributeRewards(uint256 totalAmount) external onlyOwner {
61
+ require(totalAmount > 0, "No rewards to distribute");
62
+ // Simplified: Distribute equally for demo, or based on accuracy metrics
63
+ // In real DAO, we'd use a merkle tree or tracking variable
64
+ totalDistributedRewards += totalAmount;
65
+ emit RewardsDistributed(totalAmount);
66
+ }
67
+
68
+ function claimRewards() external {
69
+ uint256 reward = claimableRewards[msg.sender];
70
+ require(reward > 0, "No rewards to claim");
71
+
72
+ claimableRewards[msg.sender] = 0;
73
+ require(trustToken.transfer(msg.sender, reward), "Transfer failed");
74
+
75
+ emit RewardsClaimed(msg.sender, reward);
76
+ }
77
+
78
+ /**
79
+ * @dev Authorities must stake tokens to be active.
80
+ */
81
+ function stake() external {
82
+ uint256 amount = MIN_STAKE;
83
+ require(trustToken.transferFrom(msg.sender, address(this), amount), "Transfer failed");
84
+
85
+ stakes[msg.sender] += amount;
86
+ isStakedReporter[msg.sender] = true;
87
+
88
+ // Auto-whitelist in registry if they stake as STANDARD
89
+ registry.setReporterStatus(msg.sender, true, ITrustRegistry.AuthorityTier.STANDARD);
90
+
91
+ emit Staked(msg.sender, amount);
92
+ }
93
+
94
+ function unstake() external {
95
+ require(stakes[msg.sender] >= MIN_STAKE, "Nothing to unstake");
96
+ uint256 amount = stakes[msg.sender];
97
+
98
+ stakes[msg.sender] = 0;
99
+ isStakedReporter[msg.sender] = false;
100
+
101
+ // Revoke reporter status
102
+ registry.setReporterStatus(msg.sender, false, ITrustRegistry.AuthorityTier.NONE);
103
+
104
+ require(trustToken.transfer(msg.sender, amount), "Transfer failed");
105
+ emit Unstaked(msg.sender, amount);
106
+ }
107
+
108
+ /**
109
+ * @dev Governance: Propose a change.
110
+ */
111
+ function createProposal(string calldata description) external {
112
+ require(isStakedReporter[msg.sender], "Only staked members can propose");
113
+
114
+ Proposal storage p = proposals[nextProposalId];
115
+ p.id = nextProposalId;
116
+ p.proposer = msg.sender;
117
+ p.description = description;
118
+ p.endTime = block.timestamp + VOTING_PERIOD;
119
+
120
+ emit ProposalCreated(nextProposalId, description);
121
+ nextProposalId++;
122
+ }
123
+
124
+ /**
125
+ * @dev Vote on a proposal using token weight.
126
+ */
127
+ function vote(uint256 proposalId, bool support) external {
128
+ Proposal storage p = proposals[proposalId];
129
+ require(block.timestamp < p.endTime, "Voting ended");
130
+ require(!p.hasVoted[msg.sender], "Already voted");
131
+
132
+ uint256 weight = trustToken.balanceOf(msg.sender);
133
+ if (isStakedReporter[msg.sender]) {
134
+ weight += stakes[msg.sender]; // Staked tokens also count
135
+ }
136
+
137
+ require(weight > 0, "No voting weight");
138
+
139
+ if (support) p.forVotes += weight;
140
+ else p.againstVotes += weight;
141
+
142
+ p.hasVoted[msg.sender] = true;
143
+ emit Voted(proposalId, msg.sender, support, weight);
144
+ }
145
+
146
+ /**
147
+ * @dev Execute a proposal (Admin only for MVP, DAO logic for production).
148
+ */
149
+ function executeProposal(uint256 proposalId) external onlyOwner {
150
+ Proposal storage p = proposals[proposalId];
151
+ require(block.timestamp >= p.endTime, "Voting ongoing");
152
+ require(!p.executed, "Already executed");
153
+ require(p.forVotes > p.againstVotes, "Proposal failed");
154
+
155
+ p.executed = true;
156
+ // In production: Execute actual target call (threshold change, etc.)
157
+ }
158
+ }
@@ -0,0 +1,23 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.0;
3
+
4
+ import "./ScoringSystem.sol";
5
+ import "./TransactionLogger.sol";
6
+ import "./ReportingSystem.sol";
7
+
8
+ /**
9
+ * @title TrustRegistry
10
+ * @dev Aggregator contract inheriting split functionality.
11
+ * Kept for backward compatibility with existing deployment scripts and frontend.
12
+ * Ideally, frontend would interact with specific contracts, but this wrapper simplifies migration.
13
+ */
14
+ contract TrustRegistry is ScoringSystem, TransactionLogger, ReportingSystem {
15
+ constructor() AccessControl() {
16
+ // Constructor logic if any necessary beyond inherited ones
17
+ // AccessControl constructor (via ScoringSystem -> AccessControl) sets msg.sender as reporter
18
+ }
19
+
20
+ // Wrapper functions if needed to expose inherited public functions generally work automatically.
21
+ // However, Solidity inheritance rules for functions with same name (if any) need overrides.
22
+ // Here we have distinct functions so it should be fine.
23
+ }
@@ -0,0 +1,51 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.0;
3
+
4
+ import "@openzeppelin/contracts/access/Ownable.sol";
5
+
6
+ contract VerificationRegistry is Ownable {
7
+ enum Status { Pending, Approved, Rejected }
8
+
9
+ struct Request {
10
+ address user;
11
+ uint96 timestamp; // Packed
12
+ address company;
13
+ Status status; // Packed
14
+ string proofCid;
15
+ }
16
+
17
+ Request[] public requests;
18
+ // Removed redundant mappings for gas optimization (use events instead)
19
+
20
+ event VerificationRequested(uint256 indexed requestId, address indexed user, address indexed company, string proofCid);
21
+ event VerificationProcessed(uint256 indexed requestId, Status status, address reviewer);
22
+
23
+ constructor() Ownable(msg.sender) {}
24
+
25
+ function requestVerification(address company, string calldata proofCid) external {
26
+ uint256 requestId = requests.length;
27
+ requests.push(Request({
28
+ user: msg.sender,
29
+ timestamp: uint96(block.timestamp),
30
+ company: company,
31
+ status: Status.Pending,
32
+ proofCid: proofCid
33
+ }));
34
+
35
+ emit VerificationRequested(requestId, msg.sender, company, proofCid);
36
+ }
37
+
38
+ function processVerification(uint256 requestId, Status status) external {
39
+ require(requestId < requests.length, "Invalid request ID");
40
+ Request storage req = requests[requestId];
41
+ require(msg.sender == req.company, "Only the assigned company can process");
42
+ require(req.status == Status.Pending, "Already processed");
43
+
44
+ req.status = status;
45
+ emit VerificationProcessed(requestId, status, msg.sender);
46
+ }
47
+
48
+ function getRequestCount() external view returns (uint256) {
49
+ return requests.length;
50
+ }
51
+ }
@@ -0,0 +1,38 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.0;
3
+
4
+ import "./IdentityVault.sol";
5
+
6
+ contract ZKIdentityVerifier is IdentityVault {
7
+
8
+ event IdentityVerified(address indexed verifier, uint256 indexed nullifierHash);
9
+
10
+ constructor(address _registry) IdentityVault(_registry) {}
11
+
12
+ // Mock Verifier function (since we can't compile real Circom verifier in this env)
13
+ // In production, this would use the Pairing library to check Groth16 proofs.
14
+ function verifyProof(
15
+ uint256[2] memory a,
16
+ uint256[2][2] memory b,
17
+ uint256[2] memory c,
18
+ uint256[2] memory input
19
+ ) public pure returns (bool) {
20
+ // MOCK: Validates if the first input (commitment) is non-zero
21
+ // Real implementation would utilize the 'verifier.sol' generated by SnarkJS
22
+ return input[0] != 0;
23
+ }
24
+
25
+ function proveIdentity(
26
+ uint256[2] memory a,
27
+ uint256[2][2] memory b,
28
+ uint256[2] memory c,
29
+ uint256[2] memory input // [commitmentHash, nullifierHash]
30
+ ) external {
31
+ require(verifyProof(a, b, c, input), "Invalid ZK Proof");
32
+
33
+ // This proves the user knows the secret behind 'commitmentHash'
34
+ // without revealing the secret itself.
35
+
36
+ emit IdentityVerified(msg.sender, input[1]);
37
+ }
38
+ }