- Add comprehensive database migrations (001-024) for schema evolution - Enhance API schema with expanded type definitions and resolvers - Add new middleware: audit logging, rate limiting, MFA enforcement, security, tenant auth - Implement new services: AI optimization, billing, blockchain, compliance, marketplace - Add adapter layer for cloud integrations (Cloudflare, Kubernetes, Proxmox, storage) - Update Crossplane provider with enhanced VM management capabilities - Add comprehensive test suite for API endpoints and services - Update frontend components with improved GraphQL subscriptions and real-time updates - Enhance security configurations and headers (CSP, CORS, etc.) - Update documentation and configuration files - Add new CI/CD workflows and validation scripts - Implement design system improvements and UI enhancements
130 lines
3.7 KiB
Solidity
130 lines
3.7 KiB
Solidity
// SPDX-License-Identifier: MIT
|
|
pragma solidity ^0.8.24;
|
|
|
|
/**
|
|
* @title IdentityManagement
|
|
* @dev Smart contract for identity and access management on the blockchain
|
|
*/
|
|
contract IdentityManagement {
|
|
enum Role {
|
|
ADMIN,
|
|
USER,
|
|
VIEWER
|
|
}
|
|
|
|
struct Identity {
|
|
address accountAddress;
|
|
string userId;
|
|
string email;
|
|
string name;
|
|
Role role;
|
|
bool active;
|
|
uint256 createdAt;
|
|
uint256 updatedAt;
|
|
}
|
|
|
|
mapping(address => Identity) public identities;
|
|
mapping(string => address) public userIdToAddress;
|
|
address[] public identityAddresses;
|
|
|
|
event IdentityCreated(
|
|
address indexed accountAddress,
|
|
string indexed userId,
|
|
Role role,
|
|
uint256 timestamp
|
|
);
|
|
|
|
event IdentityUpdated(
|
|
address indexed accountAddress,
|
|
Role newRole,
|
|
uint256 timestamp
|
|
);
|
|
|
|
event IdentityDeactivated(
|
|
address indexed accountAddress,
|
|
uint256 timestamp
|
|
);
|
|
|
|
/**
|
|
* @dev Create a new identity
|
|
*/
|
|
function createIdentity(
|
|
address accountAddress,
|
|
string memory userId,
|
|
string memory email,
|
|
string memory name,
|
|
Role role
|
|
) public returns (bool) {
|
|
require(identities[accountAddress].accountAddress == address(0), "Identity already exists");
|
|
require(userIdToAddress[userId] == address(0), "User ID already exists");
|
|
|
|
identities[accountAddress] = Identity({
|
|
accountAddress: accountAddress,
|
|
userId: userId,
|
|
email: email,
|
|
name: name,
|
|
role: role,
|
|
active: true,
|
|
createdAt: block.timestamp,
|
|
updatedAt: block.timestamp
|
|
});
|
|
|
|
userIdToAddress[userId] = accountAddress;
|
|
identityAddresses.push(accountAddress);
|
|
|
|
emit IdentityCreated(accountAddress, userId, role, block.timestamp);
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* @dev Update identity role
|
|
*/
|
|
function updateIdentityRole(address accountAddress, Role newRole) public {
|
|
require(identities[accountAddress].accountAddress != address(0), "Identity does not exist");
|
|
require(identities[accountAddress].active, "Identity is not active");
|
|
|
|
identities[accountAddress].role = newRole;
|
|
identities[accountAddress].updatedAt = block.timestamp;
|
|
|
|
emit IdentityUpdated(accountAddress, newRole, block.timestamp);
|
|
}
|
|
|
|
/**
|
|
* @dev Deactivate an identity
|
|
*/
|
|
function deactivateIdentity(address accountAddress) public {
|
|
require(identities[accountAddress].accountAddress != address(0), "Identity does not exist");
|
|
|
|
identities[accountAddress].active = false;
|
|
identities[accountAddress].updatedAt = block.timestamp;
|
|
|
|
emit IdentityDeactivated(accountAddress, block.timestamp);
|
|
}
|
|
|
|
/**
|
|
* @dev Get identity by address
|
|
*/
|
|
function getIdentity(address accountAddress) public view returns (Identity memory) {
|
|
require(identities[accountAddress].accountAddress != address(0), "Identity does not exist");
|
|
return identities[accountAddress];
|
|
}
|
|
|
|
/**
|
|
* @dev Get identity by user ID
|
|
*/
|
|
function getIdentityByUserId(string memory userId) public view returns (Identity memory) {
|
|
address accountAddress = userIdToAddress[userId];
|
|
require(accountAddress != address(0), "User ID not found");
|
|
return identities[accountAddress];
|
|
}
|
|
|
|
/**
|
|
* @dev Check if address has role
|
|
*/
|
|
function hasRole(address accountAddress, Role role) public view returns (bool) {
|
|
Identity memory identity = identities[accountAddress];
|
|
return identity.active && identity.role == role;
|
|
}
|
|
}
|
|
|