Pre-registration of username Signature Structure
To authorize the preRegistrationUsername
operation, the user (_user
) must generate a cryptographic signature compliant with the EIP-191 standard.
The signature is created by signing a precisely formatted string message derived from the pre-registration details.
Signed Message Format
The message is constructed by concatenating the following components as strings, separated by commas (,
):
string.concat(
"5d232a55",
",",
AdvancedStrings.bytes32ToString(_hashUsername),
",",
Strings.toString(_nameServiceNonce)
);
Message Components
1. Function Selector (Hex String):
- Value:
5d232a55
- Purpose: Identifies the
preRegistrationUsername
function within the EIP-191 framework
2. Username Hash (String):
- Value: The result of
AdvancedStrings.bytes32ToString(_hashUsername)
- Purpose: String representation of the
bytes32
hash commitment being pre-registered
3. Name Service Nonce (String):
- Value: The result of
Strings.toString(_nameServiceNonce)
- Purpose: Provides replay protection for pre-registration actions by the user
Example
Here's a practical example of constructing a signature message for pre-registering a username:
Scenario: User wants to pre-register the username "alice" with a secret clowNumber
Parameters:
- Username:
"alice"
- ClowNumber:
123456789
(secret value) _hashUsername
:keccak256(abi.encodePacked("alice", 123456789))
=0xa1b2c3d4e5f6789abcdef123456789abcdef123456789abcdef123456789abcdef
_nameServiceNonce
:15
Resulting message string:
5d232a55,0xa1b2c3d4e5f6789abcdef123456789abcdef123456789abcdef123456789abcdef,15
Message breakdown:
5d232a55
- Function selector for preRegistrationUsername0xa1b2c3d4e5f6789abcdef123456789abcdef123456789abcdef123456789abcdef
- Hash of username and clowNumber15
- Name Service nonce
AdvancedStrings.bytes32ToString
converts a bytes32 value to a lowercase hexadecimal string with "0x" prefixStrings.toString
converts a number to a string- The
_hashUsername
must be calculated askeccak256(abi.encodePacked(_username, _clowNumber))
- The
_clowNumber
is a secret value that must be remembered for the registration step - The function selector
5d232a55
identifies this specific Name Service operation
Hash Username Structure
For pre-registration of a username, users must provide a hash of the username. The hash is calculated using keccak256 with the following structure:
keccak256(abi.encodePacked(_username, _clowNumber));
Where:
_username
is the desired username (string)_clowNumber
is the secret key number (uint256) that will be used in theregistrationUsername
function
Important: The _clowNumber
must be kept secret during pre-registration and revealed during the actual registration process.