Introduction

Hi, I'm cardene, a software engineer and technical writer focused on blockchain and AI.

I've also authored Japanese technical books on specification-driven development with LLMs and decentralized application (DApp) development.

I also build and publish a variety of tools, libraries, and open-source projects.

This article examines ERC-7231, a proposed mechanism for aggregating Web2 and Web3 identities into an NFT with the user's authorization.

This article translates, summarizes, and expands on the following specification.

As of the original publication date, December 16, 2023, ERC-7231 was in Last Call. This is a historical status, not a statement of its current status.

More ERC explainers:

Overview

The proposal extends ERC-721. Its main objective is to link a person's identities from both the conventional Internet (Web2) and blockchain-based applications (Web3) to non-fungible tokens (NFTs), including soulbound tokens (SBTs).

For an introduction to ERC-721, see the following article.

https://chaldene.net/erc721

In practical terms, a token can represent information about a user's online identity and activities. For example, an application could associate attestations about social media activity or an account at a particular service with the NFT. This does not require storing login credentials in the NFT.

The process starts by adding a structured schema to the token metadata. A hash representing the identity information can then be updated and verified through an on-chain contract.

The NFT can thus serve as a reference to associated identity information rather than merely representing a digital asset.

The standard aims to make online identity and activity information verifiable through blockchain tokens and usable across applications. Its goal is to support more useful, user-controlled online experiences.

Motivation

An important property of Web3 is that a person can use the same identity across different applications. Users may control their accounts without depending entirely on a centralized administrator and can authorize disclosure of relevant information to different applications.

ENS, the Ethereum Name Service, provides an open, decentralized naming system useful to Ethereum applications. However, pseudonymous names alone do not provide a standardized means of validating all underlying identity information.

The proposal also discusses limitations of some SBT-based approaches, including reliance on centralized attestors, data integrity concerns, and difficulties recording information in a privacy-preserving manner. These limitations depend on the implementation rather than applying to every SBT.

The proposed solution uses an identity-aggregated NFT, linking user-authorized Web2 and Web3 identity information to an NFT, including an SBT. It aims to enable identity information to be used across a wider range of applications in a reliable way.

Specification

Interface

Contracts conforming to the proposal must implement the following interface.

javascript
// SPDX-License-Identifier: CC0-1.0
pragma solidity ^0.8.15;

interface IERC7231 {

    /**
     * @notice emit the use binding informain
     * @param id nft id 
     * @param identitiesRoot new identity root
     */
    event SetIdentitiesRoot(
        uint256 id,
        bytes32 identitiesRoot
    );

    /**
     * @notice 
     * @dev set the user ID binding information of NFT with identitiesRoot
     * @param id nft id 
     * @param identitiesRoot multi UserID Root data hash
     * MUST allow external calls
     */
    function setIdentitiesRoot(
        uint256 id,
        bytes32 identitiesRoot
    ) external;

    /**
     * @notice 
     * @dev get the multi-userID root by  NFTID
     * @param id nft id 
     * MUST return the bytes32 multiUserIDsRoot
     * MUST NOT modify the state
     * MUST allow external calls
     */
    function getIdentitiesRoot(
        uint256 id
    ) external returns(bytes32);

    /**
     * @notice 
     * @dev verify the userIDs binding 
    * @param id nft id 
     * @param userIDs userIDs for check
     * @param identitiesRoot msg hash to veriry
     * @param signature ECDSA signature 
     * MUST If the verification is passed, return true, otherwise return false
     * MUST NOT modify the state
     * MUST allow external calls
     */
    function verifyIdentitiesBinding(
        uint256 id,address nftOwnerAddress,string[] memory userIDs,bytes32 identitiesRoot, bytes calldata signature
    ) external returns (bool);
}

SetIdentitiesRoot

javascript
event SetIdentitiesRoot(
    uint256 id,
    bytes32 identitiesRoot
);

Overview

An event emitted when a new identity root is associated with an NFT ID.

Details

SetIdentitiesRoot records updates to the identity root for a particular NFT. External observers can track changes to that association through the event.

Parameters

  • id
    • The NFT's unique identifier.
  • identitiesRoot
    • The newly associated root hash of the identity information.

setIdentitiesRoot

javascript
function setIdentitiesRoot(
    uint256 id,
    bytes32 identitiesRoot
) external;

Overview

Sets the root representing the user identity bindings associated with an NFT.

Details

Associates the specified NFT ID with identitiesRoot, a hash representing multiple pieces of user identity information.

Parameters

  • id
    • The NFT's unique identifier.
  • identitiesRoot
    • The root hash of the identity information being bound.

getIdentitiesRoot

javascript
function getIdentitiesRoot(
    uint256 id
) external returns(bytes32);

Overview

Retrieves the identity root associated with a specified NFT ID.

Details

Returns the identitiesRoot for that NFT. The operation is intended to retrieve information without modifying state and must be externally callable. The original interface snippet does not explicitly declare the view modifier.

Parameters

  • id
    • The NFT's unique identifier.

Returns

  • bytes32
    • The associated identity root hash.

verifyIdentitiesBinding

javascript
function verifyIdentitiesBinding(
    uint256 id,
    address nftOwnerAddress,
    string[] memory userIDs,
    bytes32 identitiesRoot,
    bytes calldata signature
) external returns (bool);

Overview

Verifies the supplied information to determine whether the user identities are correctly bound.

Details

The function receives the NFT ID, NFT owner's address, array of user IDs, identity root, and signature. It verifies the binding and returns true on success or false otherwise.

The verification is intended to be externally callable and not to modify state.

Parameters

  • id
    • The NFT's unique identifier.
  • nftOwnerAddress
    • The NFT owner's address.
  • userIDs
    • The array of user IDs to verify.
  • identitiesRoot
    • The identity root used in verifying the message hash.
  • signature
    • The signature supplied for verification, described as an ECDSA signature in the original explanation.

Returns

  • bool
    • Whether verification succeeded.

Metadata JSON schema

json
{
  "title": "Asset Metadata",
  "type": "object",
  "properties": {
    "name": {
      "type": "string",
      "description": "Identifies the asset to which this NFT represents"
    },
    "description": {
      "type": "string",
      "description": "Describes the asset to which this NFT represents"
    },
    "image": {
      "type": "string",
      "description": "A URI pointing to a resource with mime type image"
    },
    "MultiIdentities": [
      {
        "userID": {
          "type": "string",
          "description": "User ID of Web2 and web3(DID)"
        },
        "verifierUri": {
          "type": "string",
          "description": "Verifier Uri of the userID"
        },
        "memo": {
          "type": "string",
          "description": "Memo of the userID"
        },
        "properties": {
          "type": "object",
          "description": "properties of the user ID information"
        }
      }
    ]
  }
}

The JSON defines a schema for describing the asset represented by an NFT.

  • name
    • Identifies the name of the represented asset.
  • description
    • Describes the asset.
  • image
    • A URI referencing an image resource.

The schema also includes a MultiIdentities array containing multiple user identity records. Each record has the following fields.

  • userID
    • A Web2 or Web3 user identifier, including decentralized identifiers (DIDs).
  • verifierUri
    • A URI for the identity verifier.
  • memo
    • Additional notes about the user identifier.
  • properties
    • An object containing properties of the identity information.

The metadata schema provides structured information about identities and other attributes associated with the NFT. The fields specify their data types, such as strings or objects, and descriptions explaining their meaning.

This structure makes the relationship between the NFT and associated data explicit.

Additional explanation

The proposal provides a way to integrate identities used in conventional Web2 applications and blockchain-based Web3 applications.

Identity-aggregated NFT flow

1. Combine Web2 and Web3 identities

By including the MultiIdentities schema in NFT metadata, an application can associate several identity records with an NFT. User IDs from different Web2 platforms and decentralized identifiers from Web3 can be linked to one NFT ID.

This corresponds to the "ERC-721 Metadata JSON Schema" section in the upper-right corner of the diagram. JSON data containing information associated with a person is linked to the NFT.

2. Give users control over their identity data

After configuring the metadata, a user can use setIdentitiesRoot to associate a hash representing the user IDs with the NFT ID.

The intended authorization model restricts who can establish that association. Actual ownership and access-control guarantees depend on the contract implementation and the identity verification process.

This corresponds to "Set Multi-Identities when modify the metadata" in the upper-middle part of the diagram. The previously defined JSON information is associated with the user's identities.

3. Verify on-chain and off-chain relationships through ERC-1271-compatible signatures

The proposal's verification process connects on-chain information, such as NFT ownership, with off-chain information, such as user IDs. The original explanation discusses ERC-1271 signature verification and the following checks.

  • Whether the stated NFT owner is correct.
  • Whether the user identifiers have the expected format.
  • Whether the identity root is consistent with the supplied information.
  • Whether the owner's signature is valid.

This corresponds to "Verify the binding relationship through verifierUri" in the lower-middle part of the diagram. Multiple verification steps establish relationships between on-chain and off-chain data.

These mechanisms aim to support user-controlled identity information and verifiable interactions across applications.

Backward compatibility

Tests

The test file is available here.

https://eips.ethereum.org/assets/eip-7231/test/erc7231.ts

The original test commands are as follows.

bash
cd ../assets/eip-7231
npm install
npx hardhat test

Reference implementation

javascript
// SPDX-License-Identifier: CC0-1.0
pragma solidity ^0.8.17;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";

import "@openzeppelin/contracts/utils/cryptography/SignatureChecker.sol";
import { StrSlice, toSlice } from "@dk1a/solidity-stringutils/src/StrSlice.sol";


import "./interfaces/IERC7231.sol";


contract ERC7231 is IERC7231,ERC721 {

    using { toSlice } for string;
    mapping (uint256 => bytes32) _idMultiIdentitiesRootBinding;
    mapping(uint256 => mapping(bytes32 => bool)) internal _idSignatureSetting;

    constructor(string memory _name, string memory _symbol) ERC721(_name, _symbol) {}

    /**
     * @dev Checks if the sender owns NFT with ID tokenId
     * @param id   NFT ID of the signing NFT
     */
    modifier onlyTokenOwner(uint256 id) {
        //nft owner check
        require(ownerOf(id) == msg.sender,"nft owner is not correct");
        _;
    }


    /**
     * @notice 
     * @dev set the user ID binding information of NFT with multiIdentitiesRoot
     * @param id nft id 
     * @param multiIdentitiesRoot multi UserID Root data hash
     */
    function setIdentitiesRoot(
        uint256 id,
        bytes32 multiIdentitiesRoot
    ) external {

        _idMultiIdentitiesRootBinding[id] = multiIdentitiesRoot;
        emit SetIdentitiesRoot(id,multiIdentitiesRoot);
    }
    
    /**
     * @notice 
     * @dev Update the user ID binding information of NFT
     * @param id nft id 
     */
    function getIdentitiesRoot(
        uint256 id
    ) external view returns(bytes32){

        return _idMultiIdentitiesRootBinding[id];
    }

    /**
     * @notice 
     * @dev verify the userIDs binding 
     * @param id nft id 
     * @param multiIdentitiesRoot msg hash to veriry
     * @param userIDs userIDs for check
     * @param signature ECDSA signature 
     */
    function verifyIdentitiesBinding(
        uint256 id,address nftOwnerAddress,string[] memory userIDs,bytes32 multiIdentitiesRoot, bytes calldata signature
    ) external view returns (bool){

        //nft ownership validation
        require(ownerOf(id) == nftOwnerAddress,"nft owner is not correct");

        //multi-identities root consistency validation
        require(_idMultiIdentitiesRootBinding[id] == multiIdentitiesRoot,"");

        //user id format validtion
        uint256 userIDLen = userIDs.length;
        require(userIDLen > 0,"userID cannot be empty");

        for(uint i = 0 ;i < userIDLen ;i ++){
            _verifyUserID(userIDs[i]);
        }

        //signature validation from nft owner
        bool isVerified = SignatureChecker.isValidSignatureNow(msg.sender,multiIdentitiesRoot,signature);
        return isVerified;

    }

    /**
     * @notice 
     * @dev verify the userIDs binding 
     * @param userID nft id 
     */
    function _verifyUserID(string memory userID) internal view{

        require(bytes(userID).length > 0,"userID can not be empty");

        //first part(encryption algorithm or did) check
        string memory strSplit = ":";
        bool found;
        StrSlice left;
        StrSlice right = userID.toSlice();
        (found, left, right) = right.splitOnce(strSplit.toSlice());
        require(found,"the first part delimiter does not exist");
        require(bytes(left.toString()).length > 0,"the first part does not exist");

        //second part(Organization Information) check
        (found, left, right) = right.splitOnce(strSplit.toSlice());
        require(found,"the second part delimiter does not exist");
        require(bytes(left.toString()).length > 0,"the second part does not exist");

        //id hash check
        require(bytes(right.toString()).length == 64,"id hash length is not correct");

    }

    /**
     * @dev ERC-165 support
     */
    function supportsInterface(
        bytes4 interfaceId
    ) public view virtual override returns (bool) {
        return
            interfaceId == type(IERC7231).interfaceId ||
            super.supportsInterface(interfaceId);
    }

}

Security considerations

The proposal aims to give individuals greater control over their identities, wallets, and associated data. Users can manage NFTs in their wallets and update identity associations where the implementation permits it.

For example, a user might associate identity information with an NFT when accessing a new service, then remove the association when it is no longer needed.

However, user authorization does not automatically guarantee confidentiality. Public on-chain data and previously disclosed metadata may remain accessible even after an identity root is updated. Removing a token or metadata association does not erase blockchain history or copies retained by third parties.

Applications should minimize sensitive information in public metadata, consider who can access off-chain records, and distinguish identity-binding verification from independent verification of the underlying identity claims.

Citation

Chloe Gu chloe@carv.io, Navid X. (@xuxinlai2002), Victor Yu victor@carv.io, Archer H., "ERC-7231: Identity-aggregated NFT [DRAFT]," Ethereum Improvement Proposals, no. 7231, June 2023. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-7231.

Conclusion

ERC-7231 proposes aggregating authorized Web2 and Web3 identities into NFTs. It introduces metadata and root-verification mechanisms for associating identity information with a token.

If you have questions, feel free to contact me via Twitter.

Twitter @cardene777

I also publish material on the following platforms.

https://chaldene.net/