Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
@adraffy/ens-normalize
Advanced tools
@adraffy/ens-normalize is an npm package designed to normalize Ethereum Name Service (ENS) names. It ensures that ENS names are in a consistent format, which is crucial for avoiding ambiguities and ensuring compatibility across different systems.
Normalization
This feature allows you to normalize an ENS name to ensure it is in a consistent format. The code sample demonstrates how to normalize the ENS name 'example.eth'.
const { normalize } = require('@adraffy/ens-normalize');
const normalized = normalize('example.eth');
console.log(normalized);
Validation
This feature allows you to validate an ENS name to check if it conforms to the expected format. The code sample demonstrates how to validate the ENS name 'example.eth'.
const { validate } = require('@adraffy/ens-normalize');
const isValid = validate('example.eth');
console.log(isValid);
Unicode Handling
This feature allows you to convert Punycode-encoded ENS names to their Unicode equivalents. The code sample demonstrates how to convert the Punycode-encoded ENS name 'xn--exmple-cua.eth' to its Unicode equivalent.
const { toUnicode } = require('@adraffy/ens-normalize');
const unicodeName = toUnicode('xn--exmple-cua.eth');
console.log(unicodeName);
The eth-ens-namehash package is another tool for generating ENS namehashes. It includes some basic normalization features but is primarily focused on the namehashing process. It is less comprehensive in normalization compared to @adraffy/ens-normalize.
The punycode package provides utilities for converting between Unicode and Punycode, which is useful for handling internationalized domain names (IDNs). While it does not specifically target ENS names, it can be used in conjunction with other packages to handle Unicode normalization.
0-dependancy Compact ES6 Ethereum Name Service (ENS) Name Normalizer that works in the browser.
NFC
Implementation (or use native)
15.0.0
Normalization Tests27KB
— native NFC
via nf-native.js using String.normalize()
35KB
Default — custom NFC
via nf.js41KB
Everything! — custom NFC
+ sub-libraries: parts.js, utils.jsimport {ens_normalize} from '@adraffy/ens-normalize';
// npm i @adraffy/ens-normalize
// browser: https://cdn.jsdelivr.net/npm/@adraffy/ens-normalize@latest/dist/index.min.js
// *** ALL errors throw by this library are safe to print ***
// string -> string
// throws on invalid names
// output ready for namehash
let normalized = ens_normalize('RaFFY🚴♂️.eTh');
// => "raffy🚴♂.eth"
// note: does not enforce .eth TLD 3-character minimum
Format names with fully-qualified emoji:
// works like ens_normalize
// output ready for display
let pretty = ens_beautify('1⃣2⃣.eth');
// => "1️⃣2️⃣.eth"
// note: normalization is unchanged:
// ens_normalize(ens_beautify(x)) == ens_normalize(x)
Normalize name fragments for substring search:
// these fragments fail ens_normalize() due to positional rules
// but will normalize fine as fragments
let frag1 = ens_normalize_fragment('AB--');
let frag2 = ens_normalize_fragment('\u{303}');
Input-based tokenization:
// string -> Token[]
// never throws
let tokens = ens_tokenize('_R💩\u{FE0F}a\u{FE0F}\u{304}\u{AD}./');
// [
// { type: 'valid', cp: 95 }, // valid
// { // (eg. no combining marks)
// type: 'mapped',
// cp: 82, // input
// cps: [ 114 ] // output
// },
// {
// type: 'emoji',
// input: Emoji(2) [ 128169, 65039 ], // input
// emoji: [ 128169, 65039 ], // fully-qualified
// cps: Emoji(1) [ 128169 ] // output
// },
// {
// type: 'nfc',
// input: [ 97, 772 ], // input (before nfc, only valid or mapped)
// cps: [ 257 ], // output (after nfc)
// tokens: [ // tokens (before nfc)
// { type: 'valid', cps: [ 97 ] },
// { type: 'ignored', cp: 65039 },
// { type: 'valid', cps: [ 772 ] }
// ]
// },
// { type: 'ignored', cp: 173 },
// { type: 'stop', cp: 46 },
// { type: 'disallowed', cp: 47 }
// ]
// note: if name is normalizable, then:
// ens_normalize(ens_tokenize(name).map(token => {
// ** convert valid/mapped/nfc/stop to string **
// }).join('')) == ens_normalize(name)
Output-based tokenization:
// string -> Label[]
// never throws
let labels = ens_split('💩Raffy.eth_');
// [
// {
// input: [ 128169, 82, 97, 102, 102, 121 ],
// offset: 0, // index of codepoint, not substring index!
// // (corresponding length can be inferred from input)
// tokens: [
// Emoji(2) [ 128169, 65039 ], // emoji
// [ 114, 97, 102, 102, 121 ] // nfc-text
// ],
// output: [ 128169, 114, 97, 102, 102, 121 ],
// emoji: true,
// type: 'Latin'
// },
// {
// input: [ 101, 116, 104, 95 ],
// offset: 7,
// tokens: [ [ 101, 116, 104, 95 ] ],
// output: [ 101, 116, 104, 95 ],
// emoji: false,
// error: Error('underscore only allowed at start')
// }
// ]
Generate a sorted array of supported emoji codepoints:
// () -> number[][]
console.log(ens_emoji());
// [
// [ 2764 ],
// [ 128169, 65039 ],
// [ 128105, 127997, 8205, 9877, 65039 ],
// ...
// ]
Determine if a character shouldn't be printed directly:
// number -> bool
console.log(should_escape(0x202E)); // eg. RIGHT-TO-LEFT OVERRIDE => true
Determine if a character is a printable combining mark:
// number -> bool
console.log(is_combining_mark(0x20E3)); // eg. COMBINING ENCLOSING KEYCAP => true
git clone
this repo, then npm install
npm run derive
npm run make
— compress data files from /derive/output/
npm run validate
npm run test
— perform validation testsnpm run build
— create /dist/
npm run rebuild
— run all the commands abovenpm run order
— create optimal ordering and rebuild againFAQs
Ethereum Name Service (ENS) Name Normalizer
The npm package @adraffy/ens-normalize receives a total of 808,493 weekly downloads. As such, @adraffy/ens-normalize popularity was classified as popular.
We found that @adraffy/ens-normalize demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.