-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: [sc-25504] Proposed "maturity" next steps for NameGuard JS (#347)
* rename endpoint to nameguardEndpoint * document emoji functions * move normalized graphemes to data * format docstrings * document countGraphemes * rename impersonation status to impersonation estimate * remove magic number * use isCharacter * remove charCount re-export * warn about unset env vars * fix nameguard tests * nameguard js lazy init * fix pnpm build * organize nameguard sdk tests * Add changesets * test isCombiningChar * explain impersonation tests * interface for impersonation tests * fix renamed impersonation status --------- Co-authored-by: kwrobel.eth <[email protected]> Co-authored-by: lightwalker.eth <[email protected]>
- Loading branch information
1 parent
f6cbe5d
commit 47de3ad
Showing
29 changed files
with
497 additions
and
326 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
"@namehash/nameguard": minor | ||
--- | ||
|
||
- Rename `ImpersonationStatus` to `ImpersonationEstimate` to better manage expectations. | ||
- Rename `endpoint` param to `nameguardEndpoint` when creating a NameGuard Client for more self-documenting code. | ||
- Refined unit tests. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
"@namehash/nameguard-js": minor | ||
--- | ||
|
||
- Optimize startup time by lazily initializing in-memory data models. | ||
- Refine documentation. | ||
- Refine unit tests. | ||
- Warn about likely timeout errors if Etherum provider environment variable is not set when - running unit tests. | ||
- Upgrade to the latest NameGuard SDK. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
// string[] | ||
import COMBINING_ from "./combining.json"; | ||
|
||
/** | ||
* Array of characters classified as "Combining" according to the Unicode Standard version 15.1.0. | ||
* Data is taken from https://unicode.org/. | ||
*/ | ||
export const COMBINING: Set<string> = new Set(COMBINING_ as string[]); | ||
export let COMBINING: Set<string> | null = null; | ||
|
||
export function initializeCombining() { | ||
const COMBINING_: string[] = require("./combining.json"); | ||
COMBINING = new Set(COMBINING_); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
import HANGUL_JAMO_ from './hangul_jamo.json'; | ||
|
||
/** | ||
* Contains all Hangul Jamo characters. | ||
* Data is taken from https://unicode.org/ using Unicode version 15.1.0. | ||
* This set is used in grapheme splitting to handle arbitrary Jamo sequences. | ||
*/ | ||
export const HANGUL_JAMO: Set<string> = new Set(HANGUL_JAMO_); | ||
export let HANGUL_JAMO: Set<string> | null = null; | ||
|
||
export function initializeHangulJamo() { | ||
const HANGUL_JAMO_: string[] = require("./hangul_jamo.json"); | ||
HANGUL_JAMO = new Set(HANGUL_JAMO_); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { initializeCanonicals } from "./canonicals"; | ||
import { initializeCombining } from "./combining"; | ||
import { initializeHangulJamo } from "./hangul"; | ||
import { initializeInvisibleJoiners } from "./invisible_joiners"; | ||
import { initializeUnicode } from "./unicode"; | ||
|
||
let INITIALIZED = false; | ||
|
||
/** | ||
* Initializes all data structures. | ||
* This function should be called before any other functions in this module. | ||
* It is a no-op if it has already been called. | ||
*/ | ||
export function initializeData() { | ||
if (INITIALIZED) { | ||
return; | ||
} | ||
initializeCanonicals(); | ||
initializeCombining(); | ||
initializeHangulJamo(); | ||
initializeInvisibleJoiners(); | ||
initializeUnicode(); | ||
INITIALIZED = true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
import INVISIBLE_JOINERS_ from './invisible_joiners.json'; | ||
|
||
/** | ||
* Contains invisible characters which are joined with preceding graphemes. | ||
* Data is taken from the NameHash ens-label-inspector Python package. | ||
*/ | ||
export const INVISIBLE_JOINERS: Set<string> = new Set(INVISIBLE_JOINERS_); | ||
export let INVISIBLE_JOINERS: Set<string> | null = null; | ||
|
||
export function initializeInvisibleJoiners() { | ||
const INVISIBLE_JOINERS_: string[] = require("./invisible_joiners.json"); | ||
INVISIBLE_JOINERS = new Set(INVISIBLE_JOINERS_); | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,31 @@ | ||
import { describe, it, expect } from "vitest"; | ||
import { computeImpersonationStatus } from "./impersonation"; | ||
import { describe, it, expect, beforeAll } from "vitest"; | ||
import { computeImpersonationEstimate } from "./impersonation"; | ||
import { initializeData } from "./data"; | ||
|
||
describe("Impersonation", () => { | ||
it("should return impersonation status", () => { | ||
expect(computeImpersonationStatus("nick.eth")).toBe("unlikely"); | ||
expect(computeImpersonationStatus("nićk.eth")).toBe("potential"); | ||
expect(computeImpersonationStatus("vitalik.eth")).toBe("unlikely"); | ||
expect(computeImpersonationStatus("vitalìk.eth")).toBe("potential"); | ||
expect(computeImpersonationStatus("٧٣٧.eth")).toBe("unlikely"); | ||
expect(computeImpersonationStatus("poet.base.eth")).toBe("unlikely"); | ||
expect(computeImpersonationStatus("exampleprimary.cb.id")).toBe("unlikely"); | ||
expect(computeImpersonationStatus("888.eth")).toBe("potential"); | ||
expect(computeImpersonationStatus("❤.eth")).toBe("potential"); | ||
expect(computeImpersonationStatus("٠٠۱.eth")).toBe("potential"); | ||
expect(computeImpersonationStatus("۸۸۷۵۴۲.eth")).toBe("potential"); | ||
expect(computeImpersonationStatus("୨୨୨୨୨.eth")).toBe("potential"); | ||
expect(computeImpersonationStatus("┣▇▇▇═─.eth")).toBe("potential"); | ||
expect(computeImpersonationStatus("сбер.eth")).toBe("potential"); | ||
expect(computeImpersonationStatus("vitȧlik.eth")).toBe("potential"); | ||
expect(computeImpersonationStatus("vıtalik.eth")).toBe("potential"); | ||
expect(computeImpersonationStatus("vincξnt.eth")).toBe("unlikely"); | ||
expect(computeImpersonationStatus("hello<world>!.eth")).toBe("potential"); | ||
describe("computeImpersonationEstimate", () => { | ||
beforeAll(() => { | ||
initializeData(); | ||
}); | ||
|
||
it("should return impersonation estimate", () => { | ||
// examples taken from Python Nameguard API tests | ||
expect(computeImpersonationEstimate("nick.eth")).toBe("unlikely"); | ||
expect(computeImpersonationEstimate("nićk.eth")).toBe("potential"); | ||
expect(computeImpersonationEstimate("vitalik.eth")).toBe("unlikely"); | ||
expect(computeImpersonationEstimate("vitalìk.eth")).toBe("potential"); | ||
expect(computeImpersonationEstimate("٧٣٧.eth")).toBe("unlikely"); | ||
expect(computeImpersonationEstimate("poet.base.eth")).toBe("unlikely"); | ||
expect(computeImpersonationEstimate("exampleprimary.cb.id")).toBe("unlikely"); | ||
expect(computeImpersonationEstimate("888.eth")).toBe("potential"); | ||
expect(computeImpersonationEstimate("❤.eth")).toBe("potential"); | ||
expect(computeImpersonationEstimate("٠٠۱.eth")).toBe("potential"); | ||
expect(computeImpersonationEstimate("۸۸۷۵۴۲.eth")).toBe("potential"); | ||
expect(computeImpersonationEstimate("୨୨୨୨୨.eth")).toBe("potential"); | ||
expect(computeImpersonationEstimate("┣▇▇▇═─.eth")).toBe("potential"); | ||
expect(computeImpersonationEstimate("сбер.eth")).toBe("potential"); | ||
expect(computeImpersonationEstimate("vitȧlik.eth")).toBe("potential"); | ||
expect(computeImpersonationEstimate("vıtalik.eth")).toBe("potential"); | ||
expect(computeImpersonationEstimate("vincξnt.eth")).toBe("unlikely"); | ||
expect(computeImpersonationEstimate("hello<world>!.eth")).toBe("potential"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.