SubnodeUtils
Title: DotNS Subnode Utilities Library
General-purpose helpers for registering names that live as subnodes of another name, rather than as tokenised second-level registrations.
A subname has no token: its ownership lives in the registry record, not in the registrar's ERC-721 ledger. So it is registered through @custom:function IDotnsRegistry.setSubnodeOwner here, rather than through the tokenised mint triad of @custom:contract RegistrationUtils.
Note: security-contact: admin@parity.io
Functions
subnodeOf
Derives the subnode subLabel.parentLabel.tld.
The single source of truth for how a two-level name maps to a node: walk parentLabel
under tldNode, then subLabel under that. Consumers that need the node without
writing it (readers, validators) call this so they agree with the write path.
function subnodeOf(
bytes32 tldNode,
string memory parentLabel,
string memory subLabel
)
internal
pure
returns (bytes32 subnode);
Parameters
| Name | Type | Description |
|---|---|---|
tldNode | bytes32 | The TLD node. |
parentLabel | string | Second-level parent label, e.g. 01. |
subLabel | string | Subname label, e.g. alice. |
Returns
| Name | Type | Description |
|---|---|---|
subnode | bytes32 | Namehash of subLabel under parentLabel.tld. |
liteSubnodeOf
Derives the subnode for a lite label <stem>.<suffix>, splitting it on the
separator first.
The single place a lite label is turned into a node, shared by the write path and every reader of a lite name so the issuer and its readers agree on where a lite name lives. Callers gate on @custom:function StringUtils.isLitePersonLabelMemory beforehand, so the label is known to carry the separator this splits on.
function liteSubnodeOf(
bytes32 tldNode,
string memory liteLabel
)
internal
pure
returns (bytes32 subnode);
Parameters
| Name | Type | Description |
|---|---|---|
tldNode | bytes32 | The TLD node. |
liteLabel | string | Lite label, e.g. alice.01. |
Returns
| Name | Type | Description |
|---|---|---|
subnode | bytes32 | Namehash of the stem beneath its numeric container beneath the TLD. |
registerSubname
Registers subLabel beneath the second-level name parentLabel, minting the parent
if it does not exist yet.
Derives the parent node parentLabel.tld; when no name is registered there yet it is
minted through the registrar with the calling contract as owner, so the caller holds
the parent authority @custom:function IDotnsRegistry.setSubnodeOwner requires. The
calling contract must therefore be a registrar controller, otherwise the registrar
The parent is owned by the calling contract's address. A caller that migrates to a new address rather than upgrading in place strands every parent it minted and can no longer register subnames beneath them; the caller must upgrade in place, or hold parents under an owner whose address is stable across migrations.
parentLabel is a single label registered directly under the TLD, so the parent node
is derived as namehash(tldNode, keccak(parentLabel)); deeper parents are out of scope for
this helper.
Notes:
-
reverts: NotController. When a name already exists at the parent it must be owned by the caller, otherwise @custom:reverts NotAuthorised, so a name someone else holds is never treated as the caller's parent. Ownership of the subname is then recorded through
-
function: IDotnsRegistry.setSubnodeOwner.
persistis forwarded to the registry: when false the ownership and resolver record is written but the owner'sLabelStoreis not, and the caller writes the label into the store separately.
function registerSubname(SubnameContext memory context) internal returns (bytes32 subnode);
Parameters
| Name | Type | Description |
|---|---|---|
context | SubnameContext | Subname registration inputs. See @custom:struct SubnameContext. |
Returns
| Name | Type | Description |
|---|---|---|
subnode | bytes32 | Namehash of the registered subname. |
Structs
SubnameContext
Inputs describing a single subname registration.
Passed as a struct so call sites name each field rather than thread a positional argument list, mirroring @custom:struct RegistrationUtils.RegistrationContext.
struct SubnameContext {
IDotnsProtocolRegistry protocolRegistry;
string parentLabel;
string subLabel;
address owner;
bool persist;
}
Properties
| Name | Type | Description |
|---|---|---|
protocolRegistry | IDotnsProtocolRegistry | Protocol-level address registry used to resolve the registry and TLD. |
parentLabel | string | Second-level parent label, e.g. 01. |
subLabel | string | Subname label to register, e.g. alice. |
owner | address | Address to record as the subname owner. |
persist | bool | Whether the registry should index the subnode into the owner's LabelStore. |