normalize
Normalizes an ENS name according to ENSIP-15 (UTS-46)
normalize
Normalizes an ENS name according to ENSIP-15 (UTS-46). This handles Unicode normalization, case folding, and validation.
Import
import "github.com/ChefBingbong/viem-go/utils/ens"Usage
import "github.com/ChefBingbong/viem-go/utils/ens"
// Normalize ENS namenormalized, err := ens.Normalize("Vitalik.ETH")if err != nil { log.Fatal(err)}// "vitalik.eth"
normalized, _ = ens.Normalize("wevm.eth")// "wevm.eth"
// Panic on errornormalized = ens.MustNormalize("Vitalik.ETH")// "vitalik.eth"Returns
- Type:
(string, error)forNormalize,stringforMustNormalize
The normalized ENS name. Empty string is returned for empty input.
Parameters
name (required)
- Type:
string
The ENS name to normalize.
normalized, _ := ens.Normalize("Vitalik.ETH")// "vitalik.eth"Normalization Process
The normalization process:
- Uses IDNA profile for ENS normalization (UTS-46 processing)
- Handles Unicode normalization (NFC)
- Performs case folding (lowercase)
- Handles Punycode encoding/decoding
- Processes each label separately
- Preserves encoded labelhashes (format:
[<64 hex chars>])
Functions
Normalize
Normalizes an ENS name and returns an error if normalization fails:
normalized, err := ens.Normalize("Vitalik.ETH")
MustNormalize
Normalizes an ENS name and panics on error:
normalized := ens.MustNormalize("Vitalik.ETH")
Notes
- Empty name returns empty string
- Encoded labelhashes are preserved as-is (not normalized)
- Uses non-transitional processing for ENS compatibility
- Should be used before hashing names with
NamehashorLabelhash