Skip to content

Commit

Permalink
feat: ens utils (wevm#52)
Browse files Browse the repository at this point in the history
* feat: ens utils

* docs: ens utils

* chore: remove build validate exports
  • Loading branch information
tmm authored Feb 7, 2023
1 parent 3b0f7a4 commit 94f48bd
Show file tree
Hide file tree
Showing 24 changed files with 424 additions and 73 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ bench
actions/**
chains/**
clients/**
ens/**
public/**
test/**
utils/**
Expand Down
6 changes: 6 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"recommendations": [
"orta.vscode-twoslash-queries",
"rome.rome"
]
}
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"editor.defaultFormatter": "rome.rome",
"editor.formatOnSave": true,
"typescript.tsdk": "node_modules/typescript/lib",
"typescript.enablePromptUseWorkspaceTsdk": true
}
13 changes: 10 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"preinstall": "npx only-allow pnpm",
"prepublishOnly": "pnpm ts-node scripts/generate-package-json.ts",
"prepare": "npx simple-git-hooks",
"test": "vitest dev --coverage --no-threads",
"test": "vitest dev --no-threads",
"test:ci": "CI=true vitest --coverage --no-threads",
"test:ui": "vitest dev --ui --no-threads",
"ts-node": "node --loader esbuild-register/loader -r esbuild-register",
Expand Down Expand Up @@ -53,6 +53,11 @@
"module": "./dist/clients/index.mjs",
"default": "./dist/clients/index.js"
},
"./ens": {
"types": "./dist/ens.d.ts",
"module": "./dist/ens.mjs",
"default": "./dist/ens.js"
},
"./public": {
"types": "./dist/public.d.ts",
"module": "./dist/public.mjs",
Expand Down Expand Up @@ -87,11 +92,13 @@
"dependencies": {
"@noble/hashes": "^1.1.2",
"@wagmi/chains": "~0.2.6",
"abitype": "~0.2.5"
"abitype": "~0.3.0",
"idna-uts46-hx": "^4.1.2"
},
"devDependencies": {
"@actions/core": "^1.10.0",
"@actions/github": "^5.1.1",
"@adraffy/ens-normalize": "^1.8.9",
"@changesets/changelog-github": "^0.4.5",
"@changesets/cli": "^2.23.2",
"@testing-library/jest-dom": "^5.16.5",
Expand All @@ -112,7 +119,7 @@
"rome": "^11.0.0",
"simple-git-hooks": "^2.8.1",
"tsup": "^6.5.0",
"typescript": "^4.9.3",
"typescript": "^4.9.4",
"vite": "^3.0.4",
"vitest": "^0.25.2",
"web3": "^1.8.1"
Expand Down
62 changes: 41 additions & 21 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 1 addition & 39 deletions scripts/tsup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,10 @@ export function getConfig({ dev, ...options }: GetConfig): Options {
distSourceFile.replace(/\.js$/, '.d.ts'),
`export * from '${srcTypesFile}'`,
)
fs.copyFileSync(
distSourceFile,
distSourceFile.replace('.js', '.mjs'),
)
fs.copyFileSync(distSourceFile, distSourceFile.replace('.js', '.mjs'))
}
const exports = await generateExports(entry)
await generateProxyPackages(exports)
await validateExports(exports)
},
}

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

const exports = await generateExports(entry)
await generateProxyPackages(exports)
try {
await validateExports(exports)
} catch (error) {
// `onSuccess` can run before type definitions are created so check again if failure
// https://github.com/egoist/tsup/issues/700
if (
(error as Error).message.includes(
'File does not exist for export "types"',
)
) {
await new Promise((resolve) =>
setTimeout(async () => {
await validateExports(exports)
resolve(true)
}, 3_500),
)
} else throw error
}
},
...options,
}
Expand Down Expand Up @@ -141,22 +119,6 @@ async function generateExports(entry: string[]) {
return exports
}

/**
* Validate exports point to actual files
*/
async function validateExports(exports: Exports) {
for (const [key, value] of Object.entries(exports)) {
if (typeof value === 'string') continue
for (const [type, path] of Object.entries(value)) {
const fileExists = await fs.pathExists(path)
if (!fileExists)
throw new Error(
`File does not exist for export "${type}": "${value.default}" in "${key}."`,
)
}
}
}

/**
* Generate proxy packages files for each export
*/
Expand Down
11 changes: 8 additions & 3 deletions site/.vitepress/sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ export const sidebar: DefaultTheme.Sidebar = {
{
text: 'ENS',
items: [
{ text: 'getEnsAddress 🚧', link: '/docs/actions/public/getEnsAddress' },
{
text: 'getEnsAddress 🚧',
link: '/docs/actions/public/getEnsAddress',
},
{ text: 'getEnsName 🚧', link: '/docs/actions/public/getEnsName' },
{
text: 'getEnsResolver 🚧',
Expand Down Expand Up @@ -596,8 +599,10 @@ export const sidebar: DefaultTheme.Sidebar = {
{
text: 'ENS',
items: [
{ text: 'namehash 🚧', link: '/docs/utilities/namehash' },
{ text: 'labelhash 🚧', link: '/docs/utilities/labelhash' },
{ text: 'labelhash', link: '/docs/utilities/labelhash' },
{ text: 'namehash', link: '/docs/utilities/namehash' },

{ text: 'normalize', link: '/docs/utilities/normalize' },
],
},
{
Expand Down
31 changes: 30 additions & 1 deletion site/docs/utilities/labelhash.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,32 @@
# labelhash

TODO
Hashes ENS label.

## Import

```ts
import { labelhash } from 'viem/ens'
```

## Usage

```ts
import { labelhash } from 'viem/ens'

labelhash('eth') // [!code focus:2]
// '0x4f5b812789fc606be1b3b16908db13fc7a9adf7ca72641f84d75b47069d3d7f0'
```

## Returns

`string`

The hashed ENS label.

## Parameters

### name

- **Type:** `string`

A ENS label.
Loading

0 comments on commit 94f48bd

Please sign in to comment.