Merge pull request #1 from noman-land/npm-module
[WIP] Make into npm module
This commit is contained in:
commit
01b1b0d7d1
|
@ -5,3 +5,4 @@ dist
|
|||
coverage
|
||||
.rpt2_cache
|
||||
docs
|
||||
*.d.ts
|
||||
|
|
|
@ -1,2 +1,5 @@
|
|||
*.log
|
||||
node_modules
|
||||
tsconfig.json
|
||||
src
|
||||
__test__
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
# ENS Validation
|
||||
|
||||
Following the alorithm used for Google's IDN policy, this library can validate a ENS domain.
|
||||
Following the algorithm used for Google's IDN policy, this library can validate a ENS domain.
|
||||
|
||||
## Test
|
||||
|
||||
```sh
|
||||
yarn test
|
||||
npm test
|
||||
```
|
||||
|
||||
## Build
|
||||
|
||||
```sh
|
||||
yarn build
|
||||
npm run build
|
||||
```
|
|
@ -7,9 +7,9 @@ describe('test', () => {
|
|||
expect(validate.name).toEqual('validate');
|
||||
});
|
||||
it('should return false on an unsafe string', () => {
|
||||
expect(validate(UNSAFE_STRING)).toBeFalsy();
|
||||
expect(validate(UNSAFE_STRING, false)).toBeFalsy();
|
||||
});
|
||||
it('should return true on a safe string', () => {
|
||||
expect(validate(SAFE_STRING)).toBeTruthy();
|
||||
expect(validate(SAFE_STRING, false)).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
|
File diff suppressed because it is too large
Load Diff
14
package.json
14
package.json
|
@ -1,8 +1,7 @@
|
|||
{
|
||||
"name": "ens-validation",
|
||||
"version": "0.0.0",
|
||||
"description": "",
|
||||
"private": true,
|
||||
"name": "ens-validation-test",
|
||||
"version": "0.1.1",
|
||||
"description": "Validate ENS names",
|
||||
"main": "dist/ens-validation.umd.js",
|
||||
"module": "dist/ens-validation.es6.js",
|
||||
"typings": "src/index",
|
||||
|
@ -34,17 +33,17 @@
|
|||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/MyCryptoHQ/ens-validation.git"
|
||||
"url": "git+https://github.com/status-im/ens-validation.git"
|
||||
},
|
||||
"author": "MyCrypto <henry@mycrypto.com>",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/MyCryptoHQ/ens-validation/issues"
|
||||
"url": "https://github.com/status-im/ens-validation/issues"
|
||||
},
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"homepage": "https://github.com/MyCryptoHQ/ens-validation#readme",
|
||||
"homepage": "https://github.com/status-im/ens-validation#readme",
|
||||
"devDependencies": {
|
||||
"@types/expect": "^1.20.3",
|
||||
"@types/jest": "^22.2.3",
|
||||
|
@ -82,6 +81,7 @@
|
|||
"ts",
|
||||
"tsx"
|
||||
],
|
||||
"testURL": "http://localhost",
|
||||
"transform": {
|
||||
"\\.(ts|tsx)$": "<rootDir>/node_modules/ts-jest/preprocessor.js"
|
||||
},
|
||||
|
|
|
@ -10,7 +10,8 @@ interface CheckResultContract {
|
|||
export class CheckResult implements CheckResultContract {
|
||||
public checks: SpoofChecks = SpoofChecks.ALL_CHECKS;
|
||||
public numerics: string[] = [];
|
||||
public restrictionLevel: RestrictionLevel = RestrictionLevel.HIGHLY_RESTRICTIVE;
|
||||
public restrictionLevel: RestrictionLevel =
|
||||
RestrictionLevel.HIGHLY_RESTRICTIVE;
|
||||
public toCombinedBitmask(
|
||||
enabledChecks: number,
|
||||
): SpoofChecks | RestrictionLevel {
|
||||
|
|
|
@ -2,68 +2,68 @@ import { validate } from './index';
|
|||
|
||||
describe('test', () => {
|
||||
it('should return false when u0338 is present', () => {
|
||||
expect(validate('\u0338')).toEqual(false);
|
||||
expect(validate('\u0338', false)).toEqual(false);
|
||||
});
|
||||
it('should return false when u2027 is present', () => {
|
||||
expect(validate('\u2027')).toEqual(false);
|
||||
expect(validate('\u2027', false)).toEqual(false);
|
||||
});
|
||||
// Han (CJK Ideographs) can be mixed with Bopomofo
|
||||
it('should return true when han is mixed with bopomofo', () => {
|
||||
expect(validate('\u4e00\u311B')).toEqual(true);
|
||||
expect(validate('\u4e00\u311B', false)).toEqual(true);
|
||||
});
|
||||
// Han can be mixed with Hiragana
|
||||
it('should return true when han is mixed with hiragana', () => {
|
||||
expect(validate('\u4e00\u3077')).toEqual(true);
|
||||
expect(validate('\u4e00\u3077', false)).toEqual(true);
|
||||
});
|
||||
// Han can be mixed with Katakana
|
||||
it('should return true when han is mixed with katakana', () => {
|
||||
expect(validate('\u4e00\u30DB')).toEqual(true);
|
||||
expect(validate('\u4e00\u30DB', false)).toEqual(true);
|
||||
});
|
||||
// Han can be mixed with Korean Hangul
|
||||
it('should return true when han is mixed with hangul', () => {
|
||||
expect(validate('\u4e00\u1100')).toEqual(true);
|
||||
expect(validate('\u4e00\u1100', false)).toEqual(true);
|
||||
});
|
||||
it('should return false when deviation characters are present', () => {
|
||||
expect(validate('\u00df\u03c2\u200c\u200d')).toEqual(false);
|
||||
expect(validate('\u00df\u03c2\u200c\u200d', false)).toEqual(false);
|
||||
});
|
||||
it('should return true when input is ascii', () => {
|
||||
expect(validate('ascii.eth')).toEqual(true);
|
||||
expect(validate('ascii.eth', false)).toEqual(true);
|
||||
});
|
||||
// Latin, Cyrillic or Greek characters cannot be mixed with each other
|
||||
it('should return false when mixed scripts are present', () => {
|
||||
// latin
|
||||
expect(validate('latin')).toEqual(true);
|
||||
expect(validate('latin', false)).toEqual(true);
|
||||
// latin and cyrillic
|
||||
expect(validate('latin\u0409')).toEqual(false);
|
||||
expect(validate('latin\u0409', false)).toEqual(false);
|
||||
// latin and greek
|
||||
expect(validate('latin\u0370')).toEqual(false);
|
||||
expect(validate('latin\u0370', false)).toEqual(false);
|
||||
// greek
|
||||
expect(validate('\u0370')).toEqual(true);
|
||||
expect(validate('\u0370', false)).toEqual(true);
|
||||
// greek and cyrillic
|
||||
expect(validate('\u0370\u0409')).toEqual(false);
|
||||
expect(validate('\u0370\u0409', false)).toEqual(false);
|
||||
// cyrillic
|
||||
expect(validate('\u0409')).toEqual(true);
|
||||
expect(validate('\u0409', false)).toEqual(true);
|
||||
});
|
||||
it('should return false when cyrillic characters, which look like latin, are present', () => {
|
||||
expect(validate('асԁеһіјӏорԛѕԝхуъЬҽпгѵѡ')).toEqual(false);
|
||||
expect(validate('асԁеһіјӏорԛѕԝхуъЬҽпгѵѡ', false)).toEqual(false);
|
||||
});
|
||||
it('should return true when single numerics are present', () => {
|
||||
expect(validate('4354534534543534')).toEqual(true);
|
||||
expect(validate('4354534534543534', false)).toEqual(true);
|
||||
});
|
||||
it('should return false when mixed numerics are present', () => {
|
||||
expect(validate('1১')).toEqual(false);
|
||||
expect(validate('1১', false)).toEqual(false);
|
||||
});
|
||||
it('should return false when label matches dangerous pattern', () => {
|
||||
expect(validate('\u30fb')).toEqual(false);
|
||||
expect(validate('\u30fb', false)).toEqual(false);
|
||||
});
|
||||
it('should return false when sequence of combining marks are present', () => {
|
||||
expect(validate('\u0369\u0369\u0369')).toEqual(false);
|
||||
expect(validate('\u0369\u0369\u0369', false)).toEqual(false);
|
||||
});
|
||||
it('should return false when sequence of kana combining marks are present', () => {
|
||||
expect(validate('\u3099\u3099\u3099')).toEqual(false);
|
||||
expect(validate('\u3099\u3099\u3099', false)).toEqual(false);
|
||||
});
|
||||
it('should return false when similar to EAL list is present', () => {
|
||||
expect(validate('myethervvallet')).toEqual(false);
|
||||
expect(validate('cryptocompaare')).toEqual(false);
|
||||
expect(validate('myethervvallet', false)).toEqual(false);
|
||||
expect(validate('cryptocompaare', false)).toEqual(false);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -3,10 +3,14 @@ import { SpoofChecker } from './spoof-checker';
|
|||
|
||||
export function validate(input: string, verbose: boolean): boolean {
|
||||
try {
|
||||
if (verbose) { console.log('input:', input); }
|
||||
if (verbose) {
|
||||
console.log('input:', input);
|
||||
}
|
||||
const domain: Domain = new Domain(input);
|
||||
const checker: SpoofChecker = new SpoofChecker();
|
||||
if (verbose) { console.log('Labels: ', domain.labels); }
|
||||
if (verbose) {
|
||||
console.log('Labels: ', domain.labels);
|
||||
}
|
||||
return (
|
||||
domain.labels.every(label =>
|
||||
checker.safeToDisplayAsUnicode(label, domain.isTldAscii),
|
||||
|
|
|
@ -39,7 +39,8 @@ export interface SpoofCheckerContract {
|
|||
export class SpoofChecker implements SpoofCheckerContract {
|
||||
public status: ErrorCode = ErrorCode.ZERO_ERROR;
|
||||
public checks: SpoofChecks = SpoofChecks.ALL_CHECKS;
|
||||
public restrictionLevel: RestrictionLevel = RestrictionLevel.HIGHLY_RESTRICTIVE;
|
||||
public restrictionLevel: RestrictionLevel =
|
||||
RestrictionLevel.HIGHLY_RESTRICTIVE;
|
||||
public safeToDisplayAsUnicode(label: string, isTldAscii: boolean) {
|
||||
console.log('safeToDisplayAsUnicode', label);
|
||||
this.status = ErrorCode.ZERO_ERROR;
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
"sourceMap": true,
|
||||
"strictNullChecks": true,
|
||||
"module": "es6",
|
||||
"declaration": true,
|
||||
"allowJs": false,
|
||||
"baseUrl": "./",
|
||||
"lib": ["es2017"],
|
||||
|
|
4532
yarn-error.log
4532
yarn-error.log
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue