Skip to content

Commit 94f48bd

Browse files
authored
feat: ens utils (wevm#52)
* feat: ens utils * docs: ens utils * chore: remove build validate exports
1 parent 3b0f7a4 commit 94f48bd

24 files changed

+424
-73
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ bench
2121
actions/**
2222
chains/**
2323
clients/**
24+
ens/**
2425
public/**
2526
test/**
2627
utils/**

.vscode/extensions.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"recommendations": [
3+
"orta.vscode-twoslash-queries",
4+
"rome.rome"
5+
]
6+
}

.vscode/settings.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"editor.defaultFormatter": "rome.rome",
3+
"editor.formatOnSave": true,
4+
"typescript.tsdk": "node_modules/typescript/lib",
5+
"typescript.enablePromptUseWorkspaceTsdk": true
6+
}

package.json

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"preinstall": "npx only-allow pnpm",
2222
"prepublishOnly": "pnpm ts-node scripts/generate-package-json.ts",
2323
"prepare": "npx simple-git-hooks",
24-
"test": "vitest dev --coverage --no-threads",
24+
"test": "vitest dev --no-threads",
2525
"test:ci": "CI=true vitest --coverage --no-threads",
2626
"test:ui": "vitest dev --ui --no-threads",
2727
"ts-node": "node --loader esbuild-register/loader -r esbuild-register",
@@ -53,6 +53,11 @@
5353
"module": "./dist/clients/index.mjs",
5454
"default": "./dist/clients/index.js"
5555
},
56+
"./ens": {
57+
"types": "./dist/ens.d.ts",
58+
"module": "./dist/ens.mjs",
59+
"default": "./dist/ens.js"
60+
},
5661
"./public": {
5762
"types": "./dist/public.d.ts",
5863
"module": "./dist/public.mjs",
@@ -87,11 +92,13 @@
8792
"dependencies": {
8893
"@noble/hashes": "^1.1.2",
8994
"@wagmi/chains": "~0.2.6",
90-
"abitype": "~0.2.5"
95+
"abitype": "~0.3.0",
96+
"idna-uts46-hx": "^4.1.2"
9197
},
9298
"devDependencies": {
9399
"@actions/core": "^1.10.0",
94100
"@actions/github": "^5.1.1",
101+
"@adraffy/ens-normalize": "^1.8.9",
95102
"@changesets/changelog-github": "^0.4.5",
96103
"@changesets/cli": "^2.23.2",
97104
"@testing-library/jest-dom": "^5.16.5",
@@ -112,7 +119,7 @@
112119
"rome": "^11.0.0",
113120
"simple-git-hooks": "^2.8.1",
114121
"tsup": "^6.5.0",
115-
"typescript": "^4.9.3",
122+
"typescript": "^4.9.4",
116123
"vite": "^3.0.4",
117124
"vitest": "^0.25.2",
118125
"web3": "^1.8.1"

pnpm-lock.yaml

Lines changed: 41 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/tsup.ts

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,10 @@ export function getConfig({ dev, ...options }: GetConfig): Options {
4747
distSourceFile.replace(/\.js$/, '.d.ts'),
4848
`export * from '${srcTypesFile}'`,
4949
)
50-
fs.copyFileSync(
51-
distSourceFile,
52-
distSourceFile.replace('.js', '.mjs'),
53-
)
50+
fs.copyFileSync(distSourceFile, distSourceFile.replace('.js', '.mjs'))
5451
}
5552
const exports = await generateExports(entry)
5653
await generateProxyPackages(exports)
57-
await validateExports(exports)
5854
},
5955
}
6056

@@ -72,24 +68,6 @@ export function getConfig({ dev, ...options }: GetConfig): Options {
7268

7369
const exports = await generateExports(entry)
7470
await generateProxyPackages(exports)
75-
try {
76-
await validateExports(exports)
77-
} catch (error) {
78-
// `onSuccess` can run before type definitions are created so check again if failure
79-
// https://github.com/egoist/tsup/issues/700
80-
if (
81-
(error as Error).message.includes(
82-
'File does not exist for export "types"',
83-
)
84-
) {
85-
await new Promise((resolve) =>
86-
setTimeout(async () => {
87-
await validateExports(exports)
88-
resolve(true)
89-
}, 3_500),
90-
)
91-
} else throw error
92-
}
9371
},
9472
...options,
9573
}
@@ -141,22 +119,6 @@ async function generateExports(entry: string[]) {
141119
return exports
142120
}
143121

144-
/**
145-
* Validate exports point to actual files
146-
*/
147-
async function validateExports(exports: Exports) {
148-
for (const [key, value] of Object.entries(exports)) {
149-
if (typeof value === 'string') continue
150-
for (const [type, path] of Object.entries(value)) {
151-
const fileExists = await fs.pathExists(path)
152-
if (!fileExists)
153-
throw new Error(
154-
`File does not exist for export "${type}": "${value.default}" in "${key}."`,
155-
)
156-
}
157-
}
158-
}
159-
160122
/**
161123
* Generate proxy packages files for each export
162124
*/

site/.vitepress/sidebar.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,10 @@ export const sidebar: DefaultTheme.Sidebar = {
9090
{
9191
text: 'ENS',
9292
items: [
93-
{ text: 'getEnsAddress 🚧', link: '/docs/actions/public/getEnsAddress' },
93+
{
94+
text: 'getEnsAddress 🚧',
95+
link: '/docs/actions/public/getEnsAddress',
96+
},
9497
{ text: 'getEnsName 🚧', link: '/docs/actions/public/getEnsName' },
9598
{
9699
text: 'getEnsResolver 🚧',
@@ -596,8 +599,10 @@ export const sidebar: DefaultTheme.Sidebar = {
596599
{
597600
text: 'ENS',
598601
items: [
599-
{ text: 'namehash 🚧', link: '/docs/utilities/namehash' },
600-
{ text: 'labelhash 🚧', link: '/docs/utilities/labelhash' },
602+
{ text: 'labelhash', link: '/docs/utilities/labelhash' },
603+
{ text: 'namehash', link: '/docs/utilities/namehash' },
604+
605+
{ text: 'normalize', link: '/docs/utilities/normalize' },
601606
],
602607
},
603608
{

site/docs/utilities/labelhash.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,32 @@
11
# labelhash
22

3-
TODO
3+
Hashes ENS label.
4+
5+
## Import
6+
7+
```ts
8+
import { labelhash } from 'viem/ens'
9+
```
10+
11+
## Usage
12+
13+
```ts
14+
import { labelhash } from 'viem/ens'
15+
16+
labelhash('eth') // [!code focus:2]
17+
// '0x4f5b812789fc606be1b3b16908db13fc7a9adf7ca72641f84d75b47069d3d7f0'
18+
```
19+
20+
## Returns
21+
22+
`string`
23+
24+
The hashed ENS label.
25+
26+
## Parameters
27+
28+
### name
29+
30+
- **Type:** `string`
31+
32+
A ENS label.

0 commit comments

Comments
 (0)