LabelUtils
Title: DotNS Label Utilities Library
Canonical keccak labelhash and .dot-TLD 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.
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.
General form of @custom:function namehash; use when the parent is not the .dot TLD
(e.g. subnode derivation under a non-TLD parent in the forward registry,
or a PoP namespace root). For top-level .dot registrations prefer
Note:
function: namehash which hard-codes DOT_NODE.
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). |
namehash
Computes namehash(DOT_NODE, labelhash) via memory-safe scratch space.
Specialised to the .dot TLD; cheaper than @custom:function namehashUnder because
the parent constant is folded in at compile time.
function namehash(bytes32 labelhash_) internal pure returns (bytes32 node);
Parameters
| Name | Type | Description |
|---|---|---|
labelhash_ | bytes32 | keccak256(bytes(label)). |
Returns
| Name | Type | Description |
|---|---|---|
node | bytes32 | The node identifier under the .dot TLD. |
deriveNode
Derives (labelhash, node) from a label in one call.
Convenience combinator for registration flows: hashes the label exactly once and returns both identifiers callers need without recomputing.
function deriveNode(string calldata label) internal pure returns (bytes32 hash, bytes32 node);
Parameters
| Name | Type | Description |
|---|---|---|
label | string | Label string. |
Returns
| Name | Type | Description |
|---|---|---|
hash | bytes32 | keccak256(bytes(label)). |
node | bytes32 | namehash(DOT_NODE, hash). |
stripDotTld
Strips the configured .dot TLD suffix from a stored full name.
Returns the empty string when the input does not end in the TLD; callers treat an empty return as a "do not trust this record" signal.
function stripDotTld(string memory fullName) internal pure returns (string memory label);