Skip to content

Commit

Permalink
updated did
Browse files Browse the repository at this point in the history
  • Loading branch information
poppyseedDev committed Dec 13, 2024
1 parent bb8cbab commit 75503cb
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 17 deletions.
7 changes: 2 additions & 5 deletions hardhat/contracts/decIdentity/Diploma.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ contract Diploma is SepoliaZamaFHEVMConfig, AccessControl {

/// @dev Structure to hold encrypted diploma data
struct DiplomaData {
euint64 id; // Encrypted unique diploma ID
euint128 id; // Encrypted unique diploma ID
ebytes64 university; // Encrypted university identifier
euint16 degree; // Encrypted degree identifier
ebytes64 grade; // Encrypted grade
Expand Down Expand Up @@ -119,7 +119,7 @@ contract Diploma is SepoliaZamaFHEVMConfig, AccessControl {
if (registered[userId]) revert DiplomaAlreadyRegistered();

// Generate a new encrypted diploma ID
euint64 newId = TFHE.randEuint64();
euint128 newId = TFHE.randEuint128();

// Store the encrypted diploma data
diplomaRecords[userId] = DiplomaData({
Expand Down Expand Up @@ -202,9 +202,6 @@ contract Diploma is SepoliaZamaFHEVMConfig, AccessControl {
/// @dev Grant temporary access for graduate's data to be used in claim generation
TFHE.allowTransient(diplomaRecords[userId].degree, claimAddress);

/// @dev Ensure the sender can access this graduate's data
if (!TFHE.isSenderAllowed(diplomaRecords[userId].degree)) revert AccessNotPermitted();

/// @dev Attempt the external call and capture the result
(bool success, bytes memory data) = claimAddress.call(abi.encodeWithSignature(claimFn, userId));
if (!success) revert ClaimGenerationFailed(data);
Expand Down
3 changes: 1 addition & 2 deletions hardhat/contracts/decIdentity/IdMapping.sol
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ contract IdMapping is SepoliaZamaFHEVMConfig, Ownable2Step {
*/
function generateId() public returns (uint256) {
if (addressToId[msg.sender] != 0) revert IdAlreadyGenerated();
if (msg.sender == address(0)) revert InvalidAddress();

uint256 newId = nextId;

Expand Down Expand Up @@ -92,7 +91,7 @@ contract IdMapping is SepoliaZamaFHEVMConfig, Ownable2Step {
* @custom:throws NoAddressFound if no address is associated with the ID
*/
function getAddr(uint256 _id) public view returns (address) {
if (_id <= 0 || _id >= nextId) revert InvalidId();
if (_id == 0 || _id >= nextId) revert InvalidId();
address addr = idToAddress[_id];
if (addr == address(0)) revert NoAddressFound();
return addr;
Expand Down
12 changes: 3 additions & 9 deletions hardhat/contracts/decIdentity/PassportID.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ contract PassportID is SepoliaZamaFHEVMConfig, AccessControl {
* @param birthdate Encrypted date of birth in unix timestamp format
*/
struct Identity {
euint64 id; /// @dev Encrypted unique ID
euint128 id; /// @dev Encrypted unique ID
ebytes64 biodata; /// @dev Encrypted biodata (e.g., biometric data or hashed identity data)
ebytes64 firstname; /// @dev Encrypted first name
ebytes64 lastname; /// @dev Encrypted last name
Expand Down Expand Up @@ -108,7 +108,7 @@ contract PassportID is SepoliaZamaFHEVMConfig, AccessControl {
if (registered[userId]) revert AlreadyRegistered();

/// @dev Generate a new encrypted unique ID
euint64 newId = TFHE.randEuint64();
euint128 newId = TFHE.randEuint128();

/// @dev Store the encrypted identity data
citizenIdentities[userId] = Identity({
Expand Down Expand Up @@ -150,7 +150,7 @@ contract PassportID is SepoliaZamaFHEVMConfig, AccessControl {
* @return Tuple containing (id, biodata, firstname, lastname, birthdate)
* @custom:throws IdentityNotRegistered if no identity exists for userId
*/
function getIdentity(uint256 userId) public view virtual returns (euint64, ebytes64, ebytes64, ebytes64, euint64) {
function getIdentity(uint256 userId) public view virtual returns (euint128, ebytes64, ebytes64, ebytes64, euint64) {
if (!registered[userId]) revert IdentityNotRegistered();
return (
citizenIdentities[userId].id,
Expand Down Expand Up @@ -200,9 +200,6 @@ contract PassportID is SepoliaZamaFHEVMConfig, AccessControl {
/// @dev Grant temporary access for citizen's birthdate to be used in claim generation
TFHE.allowTransient(citizenIdentities[userId].birthdate, claimAddress);

/// @dev Ensure the sender can access this citizen's birthdate
if (!TFHE.isSenderAllowed(citizenIdentities[userId].birthdate)) revert AccessNotPermitted();

/// @dev Attempt the external call and capture the result
(bool success, bytes memory data) = claimAddress.call(abi.encodeWithSignature(claimFn, userId));
if (!success) revert ClaimGenerationFailed(data);
Expand All @@ -226,11 +223,8 @@ contract PassportID is SepoliaZamaFHEVMConfig, AccessControl {

if (keccak256(bytes(fields[i])) == keccak256(bytes("id"))) {
TFHE.allowTransient(citizenIdentities[userId].id, claimAddress);
/// @dev Ensure the sender can access this citizen's university
if (!TFHE.isSenderAllowed(citizenIdentities[userId].id)) revert AccessNotPermitted();
} else if (keccak256(bytes(fields[i])) == keccak256(bytes("birthdate"))) {
TFHE.allowTransient(citizenIdentities[userId].birthdate, claimAddress);
if (!TFHE.isSenderAllowed(citizenIdentities[userId].birthdate)) revert AccessNotPermitted();
} else {
revert InvalidField();
}
Expand Down
2 changes: 1 addition & 1 deletion hardhat/test/decIdentity/diploma.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { FhevmInstance } from "fhevmjs";

import type { Diploma, EmployerClaim, IdMapping, PassportID } from "../../types";
import { createInstance } from "../instance";
import { reencryptEbool, reencryptEbytes64, reencryptEuint8, reencryptEuint16 } from "../reencrypt";
import { reencryptEbool, reencryptEbytes64 } from "../reencrypt";
import { getSigners, initSigners } from "../signers";
import { bigIntToBytes64 } from "../utils";
import { deployEmployerClaimFixture } from "./fixture/EmployerClaim.fixture";
Expand Down

0 comments on commit 75503cb

Please sign in to comment.