-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
blockchain_integration/pi_network/decentralized_identity/DID.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
contract DecentralizedIdentity { | ||
struct Identity { | ||
string name; | ||
string email; | ||
bool exists; | ||
} | ||
|
||
mapping(address => Identity) private identities; | ||
|
||
event IdentityRegistered(address indexed user, string name, string email); | ||
event IdentityUpdated(address indexed user, string name, string email); | ||
|
||
// Register a new identity | ||
function registerIdentity(string memory _name, string memory _email) public { | ||
require(!identities[msg.sender].exists, "Identity already exists."); | ||
identities[msg.sender] = Identity(_name, _email, true); | ||
emit IdentityRegistered(msg.sender, _name, _email); | ||
} | ||
|
||
// Update existing identity | ||
function updateIdentity(string memory _name, string memory _email) public { | ||
require(identities[msg.sender].exists, "Identity does not exist."); | ||
identities[msg.sender].name = _name; | ||
identities[msg.sender].email = _email; | ||
emit IdentityUpdated(msg.sender, _name, _email); | ||
} | ||
|
||
// Retrieve identity information | ||
function getIdentity(address _user) public view returns (string memory, string memory) { | ||
require(identities[_user].exists, "Identity does not exist."); | ||
return (identities[_user].name, identities[_user].email); | ||
} | ||
|
||
// Check if identity exists | ||
function identityExists(address _user) public view returns (bool) { | ||
return identities[_user].exists; | ||
} | ||
} |