← Back to Blog

Identity.sol: The Digital Spirit Name Engine

Identity.sol: The Digital Spirit Name Engine

Identity.sol: The Digital Spirit Name Engine

The Identity.sol smart contract functions as a highly optimized, pure-logic execution module for the Pond Enterprise ecosystem. Unlike typical contracts that rely heavily on continuous state mutations, this component operates statelessly for its core functionality: it calculates outputs deterministically.

Specifically, it employs a mathematical algorithm to transform a sequential userId into a human-readable identifier known as a Digital Spirit Name. The deterministic nature of this contract guarantees that the generated names are immutable based on the current fixed list of adjectives and verbs. Expansion of these word lists is strictly gated—it will only occur if a user or entity officially funds a new project specifically targeting this upgrade, adhering to the ecosystem’s rigorous open-code funding pipeline.

D-CODE Sovereign Licence

Original SourceCode

The following smart contract source code is published under the D-CODE Licence. This license enforces strict Open Code availability. Unlike Open Source, Open Code means the code is entirely public and auditable for maximum transparency, but it explicitly prohibits unauthorized modifications, derivations, or forks of the certified logic. It requires clear attribution to POND Enterprise. Furthermore, the implementation has been officially D-Safe Certified by the DSafe.US auditing framework.

// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.24;

import "./DateUtils.sol";
import {ErrorLibrary} from "./ErrorLibrary.sol";

contract Identity {

    string[255] private adjectives;
    uint8 private nbAdjectives = 0;
    string[255] private verbs;
    uint8 private nbVerbs = 0;
    uint16 private nbPass = 0;
    uint8 private currentAdjectiveIndex = 0;
    uint8 private currentVerbIndex = 0;
    mapping(string => address) public usernames;
    mapping(address => string) public usernamesInverted;
    address private __owner;
    string private tokenName;

    constructor(string memory name) {
        __owner = msg.sender;
        tokenName = name;
    }

    function identityStats() public view returns (uint8 _nbVerbs, uint8 _nbAdjectives, uint16 _nbPass) {
        return (nbVerbs, nbAdjectives, nbPass);
    }

    function _generateUsername(uint32 userId) internal view returns (string memory) {
        uint256 _nbAdjectives = nbAdjectives;
        uint256 _nbVerbs = nbVerbs;

        // Use (userId - 1) to ensure the first user (ID 1) gets Index 0, 0
        uint256 normalizedId = userId - 1;

        uint256 verbIndex = normalizedId % _nbVerbs;
        uint256 adjIndex = (normalizedId / _nbVerbs) % _nbAdjectives;
        uint256 rollover = normalizedId / (_nbAdjectives * _nbVerbs);

        return string.concat(
            adjectives[adjIndex],
            "-",
            verbs[verbIndex],
            "-",
            tokenName,
            "-",
            DateUtils.getYearMonthString(),
            "-",
            DateUtils.uintToString(rollover)
        );
    }

    function defineCombinations(string[] calldata _adjectives, string[] calldata _verbs) public virtual {
        if (__owner != msg.sender) {
            revert ErrorLibrary.IdentityUnauthorizedAccount(msg.sender);
        }

        uint16 al = uint16(_adjectives.length);
        uint16 vl = uint16(_verbs.length);

        if (al >= 255 - nbAdjectives) {
            revert ErrorLibrary.TooManyAdjectiveDefined();
        }
        if (vl >= 255 - nbVerbs) {
            revert ErrorLibrary.TooManyVerbsDefined();
        }
        for (uint16 i = 0; i < al; i++) {
            adjectives[nbAdjectives] = _adjectives[i];
            nbAdjectives++;
        }
        for (uint16 i = 0; i < vl; i++) {
            verbs[nbVerbs] = _verbs[i];
            nbVerbs++;
        }
    }

    function usernameExists(string calldata username) public view returns (bool ok) {
        return usernames[username] != address(0);
    }

    function getAddressByUsername(string calldata username) public view returns (address addr) {
        //username deosn't exist
        if (usernames[username] == address(0)) {
            revert ErrorLibrary.UsernameNotDefined();
        }
        return usernames[username];
    }

    function getUsernameByAddress(address addr) public virtual view returns (string memory username)  {
        return usernamesInverted[addr];
    }

    function linkUsernameToAddress(address addr, string memory username) internal {
        // username already taken by an address
        if (usernames[username] != address(0)) {
            revert ErrorLibrary.UserNameAlreadyTaken();
        }
        usernames[username] = addr;
        usernamesInverted[addr] = username;
    }


}

Stay Informed on Ethical Safety

Join our newsletter to receive deep dives into smart contract security and the future of decentralized knowledge.

Subscribe to Newsletter