LabelStore

Git Source

Inherits: Initializable, ILabelStore

Title: LabelStore

Permanent per-user DotNS label store.

One instance per user, deployed as a BeaconProxy by StoreFactory during registration. Bound to its user forever: _owner and _protocolRegistry are set once at initialize and never mutate. Writes are gated to addresses currently registered in DotnsProtocolRegistry (isRegisteredAddress); every labelhash is single-write and permanently locked on first use.

Labels-only by invariant: this store holds registration records only. Every other per-name category (reverse, content, forward address, chat key, lite link) lives on a dedicated resolver, never here.

Storage collision: the BeaconProxy stores the beacon address at EIP-1967 slot keccak256("eip1967.proxy.beacon") - 1, which is non-sequential and cannot collide with this contract's sequential storage slots.

Note: security-contact: admin@parity.io

State Variables

_owner

Permanent user this store belongs to. Set in initialize.

address private _owner

_protocolRegistry

Canonical DotNS protocol registry. Set in initialize.

address private _protocolRegistry

_labels

labelhash => stored label string.

mapping(bytes32 labelhash => string label) private _labels

_labelList

Insertion-order list of all stored labelhashes. Append-only.

bytes32[] private _labelList

_labelIndex

labelhash => 1-indexed position in _labelList (zero means "not present"). Doubles as the permanent-lock sentinel: a non-zero index proves the label was written and the contract has no deletion path, so the index is also the locked flag.

mapping(bytes32 labelhash => uint256 indexPlusOne) private _labelIndex

__gap

Reserved storage space to allow for layout changes in future beacon upgrades.

uint256[50] private __gap

Functions

onlyAuthorisedProtocol

Restricts writes to protocol-registered addresses only.

modifier onlyAuthorisedProtocol() ;

constructor

Note: oz-upgrades-unsafe-allow: constructor

constructor() ;

initialize

Initialises the store, binding it permanently to user_ and protocolRegistry_.

Callable exactly once via Initializable; both parameters are immutable post-call. user_ must be non-zero, otherwise @custom:reverts InvalidUser. protocolRegistry_ must be non-zero, otherwise @custom:reverts InvalidProtocolRegistry. @param user_ The user this store is bound to forever.

function initialize(address user_, address protocolRegistry_) external override initializer;

Parameters

NameTypeDescription
user_address
protocolRegistry_addressThe protocol registry used to authorise writers.

storeLabel

Records a label under labelhash and locks the slot permanently.

Gated to addresses currently registered in the protocol registry, otherwise

Note: reverts: NotAuthorised. labelhash must be non-zero, otherwise

function storeLabel(
    bytes32 labelhash,
    string calldata label
)
    external
    override
    onlyAuthorisedProtocol;

Parameters

NameTypeDescription
labelhashbytes32The labelhash key.
labelstringThe label string to store.

owner

Returns the permanent user this store is bound to.

Set once at initialize and never mutated; used as the binding-mismatch oracle and immutable thereafter.

function owner() external view override returns (address owner_);

Returns

NameTypeDescription
owner_addressThe bound user address.

protocolRegistry

Returns the protocol registry this store queries for write authorisation.

function protocolRegistry() external view override returns (address protocolRegistry_);

Returns

NameTypeDescription
protocolRegistry_addressThe registry address.

hasLabel

Returns true iff a label has been stored under labelhash.

function hasLabel(bytes32 labelhash) external view override returns (bool exists);

Parameters

NameTypeDescription
labelhashbytes32The labelhash to check.

Returns

NameTypeDescription
existsboolTrue iff the slot holds a label.

isLocked

Returns true iff the slot for labelhash is permanently locked.

Always equal to hasLabel in the current design; exposed explicitly so future implementations behind the beacon can distinguish "stored" from "locked" if needed.

function isLocked(bytes32 labelhash) external view override returns (bool locked);

Parameters

NameTypeDescription
labelhashbytes32The labelhash to check.

Returns

NameTypeDescription
lockedboolTrue iff the slot is locked.

getLabel

Returns the stored label for labelhash, or the empty string if none.

function getLabel(bytes32 labelhash) external view override returns (string memory label);

Parameters

NameTypeDescription
labelhashbytes32The labelhash to look up.

Returns

NameTypeDescription
labelstringThe stored label string.

getLabelCount

Returns the total number of labels ever stored.

function getLabelCount() external view override returns (uint256 count);

Returns

NameTypeDescription
countuint256Current length of the insertion-order list.

getLabelAt

Returns the human-readable label at the given insertion-order index.

Primary read for "give me my names"; does not require the caller to know any labelhash. For the underlying labelhash key see @custom:function getLabelhashAt.

function getLabelAt(uint256 index) external view override returns (string memory label);

Parameters

NameTypeDescription
indexuint256Zero-based index into the insertion-order list.

Returns

NameTypeDescription
labelstringThe stored label string at index.

getLabelhashAt

Returns the labelhash at the given insertion-order index.

function getLabelhashAt(uint256 index) external view override returns (bytes32 labelhash);

Parameters

NameTypeDescription
indexuint256Zero-based index into the insertion-order list.

Returns

NameTypeDescription
labelhashbytes32The labelhash at index.

getLabels

Paginated read returning just the stored labels, in insertion order.

Primary bulk read for "give me all my names". Callers never need to touch labelhashes. Length is min(limit, getLabelCount() - offset); offset >= getLabelCount() returns an empty array (not a revert).

function getLabels(
    uint256 offset,
    uint256 limit
)
    external
    view
    override
    returns (string[] memory labels);

Parameters

NameTypeDescription
offsetuint256Start index.
limituint256Maximum entries to return.

Returns

NameTypeDescription
labelsstring[]Slice of label strings.

getLabelhashes

Paginated read over the labelhash keys, in insertion order.

Advanced read for callers that need the raw labelhash keys. Symmetric with

Note: function: getLabels; same indices map to the same entries.

function getLabelhashes(
    uint256 offset,
    uint256 limit
)
    external
    view
    override
    returns (bytes32[] memory labelhashes);

Parameters

NameTypeDescription
offsetuint256Start index.
limituint256Maximum entries to return.

Returns

NameTypeDescription
labelhashesbytes32[]Slice of labelhash keys.

version

Returns implementation version.

function version() external pure virtual returns (string memory versionString);

Returns

NameTypeDescription
versionStringstringCurrent version string.

_onlyAuthorisedProtocol

Internal authorisation check deferred from the onlyAuthorisedProtocol modifier.

function _onlyAuthorisedProtocol() internal view;