# DcnRegistry

*Address:* [*0xE9F4dfE02f895DC17E2e146e578873c9095bA293*](https://polygonscan.com/address/0xE9F4dfE02f895DC17E2e146e578873c9095bA293)

The `DcnRegistry` contract plays a pivotal role in the DCN system, providing a foundation for managing and interacting with DCN names. Built upon the ERC721 standard, the `DcnRegistry` treats each name as a unique Non-Fungible Token (NFT) ID, enabling seamless ownership, resolution, and management of DCN names.

### Manager-Exclusive Functions

Several key functions within the `DcnRegistry` are reserved for access exclusively by designated managers, such as the `DcnManager` contract. These functions include minting, minting TLDs, claiming expired names, renewing ownership periods, and setting resolvers. This design ensures a controlled and secure environment for critical operations within the DCN ecosystem.

### Resolver Management

The `DcnRegistry` facilitates the association of resolvers with individual names. Managers can utilize dedicated functions to set the resolver for a specific name, providing a seamless mechanism for resolving names to relevant data or resources.

### Information Retrieval

The contract offers a range of informative `view` functions, enabling users to access essential details about the DCN system. These functions include querying resolver information, checking the expiration status of a node, and verifying the existence of a specific node.

### Name Storage Mechanism

Names submitted for minting undergo a unique storage mechanism within the `DcnRegistry`. Upon submission, the labels of the name (in the format \["myname", "tld"]) are hashed from top to bottom, resulting in a `bytes32` variable. This `bytes32` value is then converted to a `uint256`, serving as the NFT ID uniquely associated with the submitted name. This  approach ensures the integrity and uniqueness of each DCN name while facilitating efficient and effective resolution.

```solidity
/// Iteratively calculates the name hash of a list of labels
function labelsHash(
    string[] calldata labels
) private view returns (bytes32 node) {
    require(labels.length > 1, "Labels length below 2");
    for (uint256 i = labels.length; i > 0; i--) {
        require(_exists(uint256(node)), "Parent node does not exist");
        node = namehash(node, labels[i - 1]);
    }
}

/// Calculates the name hash of a label given the parent node
function namehash(
    bytes32 node,
    string calldata label
) private pure returns (bytes32 hashed) {
    require(bytes(label).length != 0, "Empty label");
    hashed = keccak256(
        abi.encodePacked(node, keccak256(abi.encodePacked(label)))
    );
}
```

<br>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.dimo.org/protocol/device-canonical-name/contracts/dcnregistry.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
