From 5014b906bf9e2ef257ae0f30e93105b4798846d0 Mon Sep 17 00:00:00 2001 From: KOSASIH Date: Sat, 23 Nov 2024 00:54:19 +0700 Subject: [PATCH] Create DID.sol --- .../pi_network/decentralized_identity/DID.sol | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 blockchain_integration/pi_network/decentralized_identity/DID.sol diff --git a/blockchain_integration/pi_network/decentralized_identity/DID.sol b/blockchain_integration/pi_network/decentralized_identity/DID.sol new file mode 100644 index 000000000..1b28cb1d4 --- /dev/null +++ b/blockchain_integration/pi_network/decentralized_identity/DID.sol @@ -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; + } +}