LabelUtils
Title: DotNS Label Utilities Library
Canonical keccak labelhash and namehash helpers shared by every DotNS contract that derives node identifiers from user-supplied labels.
Exists so that the identical inline-assembly keccak sequences don't need to live in every controller, registrar, or resolver. Every caller that maps a label to an on-chain node goes through this library, which is the single source of truth for how a label hashes. The TLD is supplied by the caller (read from the protocol registry), so this library holds no network-specific constant.
Deliberate non-goals:
- Validation (single-label checks, min-length rules, availability): each caller owns its own validation policy alongside its own interface-declared errors. Centralising validation here would require centralising the error types, which breaks interface-level error ownership.
- Lowercase ASCII letters/digits/hyphen rules with hyphen-position constraints live in @custom:function StringUtils.isSingleLabel; this library treats the input as opaque bytes once a caller has run its own checks.
Note: security-contact: admin@parity.io
Functions
labelhash
Computes keccak256(bytes(label)) via memory-safe scratch space.
function labelhash(string calldata label) internal pure returns (bytes32 hash);
Parameters
| Name | Type | Description |
|---|---|---|
label | string | Label string. |
Returns
| Name | Type | Description |
|---|---|---|
hash | bytes32 | keccak256(bytes(label)). |
labelhashMemory
Computes keccak256(bytes(label)) for a memory string.
Overload used by call sites that hold the label in memory (e.g. the
registrar's transfer sync path reading _labels[tokenId]). Same
semantics as @custom:function labelhash, different calldata shape.
function labelhashMemory(string memory label) internal pure returns (bytes32 hash);
Parameters
| Name | Type | Description |
|---|---|---|
label | string | Label string held in memory. |
Returns
| Name | Type | Description |
|---|---|---|
hash | bytes32 | keccak256(bytes(label)). |
namehashUnder
Computes namehash(parent, labelhash) against an arbitrary parent.
Pass the TLD node (from the protocol registry) as parent for a top-level
registration, or a subnode/PoP-namespace node for a nested name.
function namehashUnder(bytes32 parent, bytes32 labelhash_)
internal
pure
returns (bytes32 node);
Parameters
| Name | Type | Description |
|---|---|---|
parent | bytes32 | Parent node. |
labelhash_ | bytes32 | keccak256(bytes(label)). |
Returns
| Name | Type | Description |
|---|---|---|
node | bytes32 | namehash(parent, labelhash). |
deriveNode
Derives (labelhash, node) for a label under a given TLD node in one call.
Convenience combinator for registration flows: hashes the label exactly once and returns both identifiers callers need without recomputing.
function deriveNode(
bytes32 tldNode,
string calldata label
)
internal
pure
returns (bytes32 hash, bytes32 node);
Parameters
| Name | Type | Description |
|---|---|---|
tldNode | bytes32 | TLD node to root the name under, read from the protocol registry. |
label | string | Label string. |
Returns
| Name | Type | Description |
|---|---|---|
hash | bytes32 | keccak256(bytes(label)). |
node | bytes32 | namehash(tldNode, hash). |
stripTld
Strips the network's TLD suffix from a stored full name.
Returns the empty string when the input does not end in tld; callers treat
an empty return as a "do not trust this record" signal.
function stripTld(
string memory tldSuffix,
string memory fullName
)
internal
pure
returns (string memory label);
Parameters
| Name | Type | Description |
|---|---|---|
tldSuffix | string | TLD suffix including the leading dot, read from the protocol registry. |
fullName | string | Stored full name to strip. |