Alert Source Discuss
Standards Track: ERC

ERC-7734: 去中心化身份验证 (DID)

一种保护隐私的去中心化身份验证方法,能够安全地将身份管理集成到 dApp 中。

Authors Anushka Yadav (@64anushka) <64anushka@gmail.com>
Created 2024-06-26

摘要

本提案介绍了区块链上的去中心化身份验证 (DID) 标准。该标准利用加密哈希来表示身份证明和事件,以实现透明度和可追溯性。通过强调简单性、隐私性和用户控制,本提案旨在减少开发者和用户的开销,确保无缝集成到去中心化应用程序 (dApp) 中。它提供了一个最小化的解决方案,使身份结构保持简单,并支持链下机制进行详细的身份管理和验证。

动机

中心化的身份验证方法繁琐、容易发生数据泄露,并且无法为用户提供对其身份数据的控制。现有的 DID 解决方案通常引入复杂性,使得开发者和用户难以采用。本提案旨在通过以下方式解决这些问题:

  • 提供一个最小化的、去中心化的标准,以简化身份验证。
  • 提供保护隐私的机制,将敏感的身份数据保留在链下。
  • 通过实现与各种行业 dApp 的无缝集成,鼓励更广泛的采用。

利益相关者

以下利益相关者将受益于本提案:

dApp 开发者

创建需要身份验证的去中心化应用程序的开发者可以实施此标准,为用户提供安全、去中心化的身份管理。最小化的设计使其更易于集成到现有工作流程中,而无需增加不必要的复杂性。

服务提供商

提供去中心化金融 (DeFi)、游戏或社交网络等服务的平台可以集成此标准,以验证用户身份,而无需依赖中心化机构。这降低了欺诈风险并增强了用户信任。

企业

希望将基于区块链的身份解决方案集成到其现有系统中的公司可以使用此标准来确保安全且保护隐私的身份验证。这允许平滑过渡到去中心化技术,同时保持用户隐私和安全。

互操作性解决方案的开发者

那些致力于跨平台和跨区块链互操作性的人员可以实施此标准,以实现跨不同系统的统一身份验证机制,从而降低复杂性并增加用户对其身份的控制。

差异化

本提案与其他 DID 标准的区别在于它侧重于极简主义、用户控制和隐私。与其他包含各种身份属性和交互的解决方案不同,此标准保持结构简单,并依赖链下机制进行详细的身份管理。它的简单性促进了更容易的采用,使其成为优先考虑以用户为中心的安全生态系统的 dApp 的理想选择。

规范

去中心化身份验证 (DID) 标准引入了一种简单、安全且保护隐私的机制,用于验证区块链上的用户身份。该标准的关键组件概述如下:

身份合约

一个智能合约,充当身份验证的中心机构。该合约存储用户的身份验证状态,并确保安全透明地触发验证事件。

验证函数

verifyIdentity 函数允许用户提交两个验证哈希,这些哈希表示链下身份证明或证明。这些哈希可以从外部来源(例如第三方验证者、文档或证明)派生。该函数比较提供的哈希并相应地更新身份验证状态。

输入参数:

identityHash: 表示用户身份的加密哈希。 verificationHash: 从用于验证身份的证明或证明中派生的加密哈希。

IdentityVerified 事件

当用户的身份验证成功更新时,会发出 IdentityVerified 事件。此事件确保可追溯性和透明度,允许 dApp 开发者和用户跟踪验证状态。

身份结构

身份是一个简单的结构,由唯一的地址(公钥)表示。其他身份属性(例如姓名或年龄)是可选的,并留给链下管理。这种最小化方法使实现保持精简,避免了不必要的复杂性并鼓励更广泛的采用。

接口

pragma solidity ^0.8.0;

interface IDecentralizedIdentity {
    // Struct to represent an identity
    struct Identity {
        address userAddress; // Ethereum address of the user
        bytes32 identityHash; // Hash of the identity data
        bytes32[2] verificationHashes; // Hashes used for verifying identity
        bool isVerified; // Indicates if the identity is verified
        uint256 timestamp; // Timestamp of identity creation
    }

    // Event emitted when a new identity is created
    event IdentityCreated(address indexed userAddress, bytes32 identityHash, uint256 timestamp);

    // Event emitted when an identity is verified
    event IdentityVerified(address indexed userAddress, bytes32[2] verificationHashes, uint256 timestamp);

    // Event emitted when an identity is revoked
    event IdentityRevoked(address indexed userAddress, uint256 timestamp);

    // Function to create a new decentralized identity for the caller.
    // Parameters:
    // - identityHash: Hash of the identity data.
    function createIdentity(bytes32 identityHash) external;

    // Function to verify the decentralized identity for the caller.
    // Parameters:
    // - verificationHashes: Hashes used for verifying the identity. These can be 
    //   derived from off-chain proofs, cryptographic challenges, or other methods 
    //   specific to the implementer's requirements. The exact meaning and derivation 
    //   of the verificationHashes are left to the contract's implementer.
    function verifyIdentity(bytes32[2] calldata verificationHashes) external;

    // Function to revoke the decentralized identity for the caller.
    function revokeIdentity() external;
    
    // Function to retrieve the decentralized identity for a given user address
    // Parameters:
    // - userAddress Ethereum address of the user.
    // Returns:
    // identity The decentralized identity struct.
    function getIdentity(address userAddress) external view returns (Identity memory);
}

原理

该设计利用加密哈希来表示身份信息,确保敏感数据不会直接存储在区块链上。使用 verificationHashes 允许灵活的身份验证机制。这些哈希可以从各种链下证明(例如加密挑战或证明)派生而来,具体取决于实施者的需求。通过保持验证哈希的解释开放,该标准实现了适应性,同时保持了隐私和安全性。此外,包含事件可确保透明度和可追溯性。

参考实现

pragma solidity ^0.8.0;

import "./IDecentralizedIdentity.sol";

contract DecentralizedIdentity is IDecentralizedIdentity {
    // Mapping to store identities by user address
    mapping(address => Identity) private identities;

    // Function to create a new decentralized identity for the caller.
    // Parameters:
    // - identityHash Hash of the identity data.
    function createIdentity(bytes32 identityHash) external override {
        // Ensure identity does not already exist
        require(identities[msg.sender].userAddress == address(0), "Identity already exists");

        // Create the identity for the caller
        identities[msg.sender] = Identity({
            userAddress: msg.sender,
            identityHash: identityHash,
            verificationHashes: [bytes32(0), bytes32(0)], // 使用空哈希初始化
            isVerified: false,
            timestamp: block.timestamp
        });

        // Emit event for the creation of a new identity
        emit IdentityCreated(msg.sender, identityHash, block.timestamp);
    }

    // Function to verify the decentralized identity for the caller.
    // Parameters:
    // - verificationHashes: Hashes used for verifying the identity.
    function verifyIdentity(bytes32[2] calldata verificationHashes) external override {
        // Ensure identity exists
        require(identities[msg.sender].userAddress != address(0), "Identity does not exist");

        // Update verification hashes and mark identity as verified
        identities[msg.sender].verificationHashes = verificationHashes;
        identities[msg.sender].isVerified = true;

        // Emit event for the verification of identity
        emit IdentityVerified(msg.sender, verificationHashes, block.timestamp);
    }

    // Function to revoke the decentralized identity for the caller.
    function revokeIdentity() external override {
        // Ensure identity exists
        require(identities[msg.sender].userAddress != address(0), "Identity does not exist");

        // Mark identity as not verified
        identities[msg.sender].isVerified = false;

        // Emit event for the revocation of identity
        emit IdentityRevoked(msg.sender, block.timestamp);
    }

    // Function to retrieve the decentralized identity for a given user address
    // Parameters:
    // - userAddress Ethereum address of the user.
    // Returns:
    // identity The decentralized identity struct.
    function getIdentity(address userAddress) external view override returns (Identity memory) {
        return identities[userAddress];
    }
}

安全考虑事项

安全哈希:确保使用安全的哈希算法生成身份和验证哈希,以防止冲突并确保身份数据的完整性。 重放攻击:验证哈希应包含 nonce 或时间戳,以防止重放攻击。 实现灵活性:开发者必须确保哈希生成和验证过程是稳健的,并且能够抵抗操纵。

版权

Copyright 和相关权利通过 CC0 放弃。

Citation

Please cite this document as:

Anushka Yadav (@64anushka) <64anushka@gmail.com>, "ERC-7734: 去中心化身份验证 (DID)," Ethereum Improvement Proposals, no. 7734, June 2024. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-7734.