ens-normalize-rs

Crates.ioens-normalize-rs
lib.rsens-normalize-rs
version0.1.1
sourcesrc
created_at2024-11-30 05:26:40.068258
updated_at2024-12-01 06:38:32.899765
descriptionEthereum Name Service (ENS) name normalization
homepage
repositoryhttps://github.com/sevenzing/ens-normalize-rs
max_upload_size
id1466321
size14,652,491
sevenzing (sevenzing)

documentation

README

ens-normalize-rs

tests

A Rust implementation of ENS (Ethereum Name Service) name normalization.

Description

ens-normalize-rs is a robust Rust library for normalizing and validating ENS names according to ENSIP-15 specifications. It handles Unicode normalization, validation, beautification of ENS names ensuring correct, consistent and idempotent behavior.

Installation

cargo add ens-normalize-rs

Or add this to your project using Cargo:

[dependencies]
ens-normalize-rs = "0.1.1"

Usage

fn main() {
    fn main() {
    // Using normalizer to reuse preloaded data
    let normalizer = ens_normalize_rs::EnsNameNormalizer::default();
    let name = "🅰️🅱.eth";
    let processed = normalizer.process(name).unwrap();
    let beautified_name = processed.beautify();
    let normalized_name = processed.normalize();

    assert_eq!(normalized_name, "🅰🅱.eth");
    assert_eq!(beautified_name, "🅰️🅱️.eth");

    // Using normalize directly
    let normalized = normalizer.normalize("Levvv.eth").unwrap();
    assert_eq!(normalized, "levvv.eth");

    // Handling errors
    assert!(matches!(
        normalizer.normalize("Levvv..eth"),
        Err(ens_normalize_rs::ProcessError::DisallowedSequence(
            ens_normalize_rs::DisallowedSequence::EmptyLabel
        ))
    ));
    assert!(matches!(
        // U+200D ZERO WIDTH JOINER
        normalizer.normalize("Ni‍ck.ETH"),
        Err(ens_normalize_rs::ProcessError::DisallowedSequence(
            ens_normalize_rs::DisallowedSequence::InvisibleCharacter(0x200d)
        ))
    ));
}
}

Testing

Crate contains several types of tests:

To run all tests simply run:

cargo test

Roadmap

  • Tokenization

  • Normalization

  • Beautification

  • ENSIP-15 Validation Tests

  • Unicode Normalization Tests

  • CLI to update specs.json and nf.json

  • analog of ens_cure function

  • analog of ens_normalizations function

License

This project is licensed under the MIT License - see the LICENSE file for details.

Commit count: 15

cargo fmt