Name processing
Last updated
Last updated
description |
---|
In place of human-readable names, ZNS works purely with fixed length 256-bit cryptographic hashes. In order to derive the hash from a name while still preserving its hierarchal properties, a process called Namehash is used. For example, the namehash of 'alice.zk' is 0x787192fc5378cc32aa956ddfdedbf26b24e8d78e40109add0eea2c1a012c3dec; this is the representation of names that is used exclusively inside ZNS.
Before being hashed with namehash, names are first normalized, using a process called UTS-46 normalization. This ensures that upper- and lower-case names are treated equivalently, and that invalid characters are prohibited. Anything that hashes and resolves a name must first normalize it, to ensure that all users get a consistent view of ZNS.
Before a name can be converted to a node hash using Namehash, the name must first be normalized and checked for validity - for instance, converting fOO.zk into foo.zk, and prohibiting names containing forbidden characters such as underscores. It is crucial that all applications follow the same set of rules for normalization and validation, as otherwise two users entering the same name on different systems may resolve the same human-readable name into two different ZNS names.
Applications using ZNS and processing human-readable names must follow UTS46 for normalization and validation. Processing should be done with non-transitional rules, and with UseSTD3ASCIIRules=true.
Namehash is a recursive process that can generate a unique hash for any valid domain name. Starting with the namehash of any domain - for example, 'alice.zk' - it's possible to derive the namehash of any subdomain - for example 'iam.alice.zk' - without having to know or handle the original human-readable name. It is this property that makes it possible for ZNS to provide a hierarchal system, without having to deal with human-readable text strings internally.
domain - The complete, human-readable form of a name; eg, iam.alice.zk.
label - A single component of a domain - eg, iam, alice.
label hash - the output of the keccak-256 function applied to a label; eg, keccak256(‘zk’) = 0x4f5b812789fc606be1b3b16908db13fc7a9adf7ca72641f84d75b47069d3d7f0
node - The output of the namehash
function, used to uniquely identify a name in ZNS.
First, a domain is divided into labels by splitting on periods (‘.’). So, ‘abc.wallet.zk’ becomes the list [‘abc’, ‘wallet’, ‘zk’].
The namehash function is then defined recursively as follows:
A sample implementation in Python is provided below.
Namehash is specified in EIP 137.
Describes how to normalize and hash ZNS names.