Skip to content

Commit

Permalink
fix: apply pr feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
tk-o committed Jan 28, 2025
1 parent 0296122 commit 0386066
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 33 deletions.
14 changes: 7 additions & 7 deletions apps/ensnode/src/lib/ids.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Labelhash, Node } from "ensnode-utils/types";
import type { Address, Hex } from "viem";
import type { Labelhash, Node, OwnedName } from "./types";

// NOTE: subgraph uses lowercase address here, viem provides us checksummed, so we lowercase it
export const makeResolverId = (address: Address, node: Hex) =>
Expand All @@ -13,7 +13,7 @@ export const makeEventId = (blockNumber: bigint, logIndex: number, transferIndex
.join("-");

/**
* Makes a cross-chain unique registration ID.
* Makes a cross-registrar unique registration ID.
*
* A Registration record's id is historically the labelhash of the label
* directly under the name the Registrar manages (i.e. for a registration
Expand All @@ -26,9 +26,9 @@ export const makeEventId = (blockNumber: bigint, logIndex: number, transferIndex
* any other Registrar use node (i.e. namehash(test.base.eth) to avoid
* collisions that would otherwise occur.
*
* @param ownedName the ownedName of the ENSNode plugin that is processing the registration event
* @param label registration's label
* @param node registration's node
* @param registrarName the name of the registrar issuing the registration
* @param labelHash the labelHash of the direct subname of `registrarName` that was registered
* @param node the node of the full name that was registered
*/
export const makeRegistrationId = (ownedName: OwnedName, label: Labelhash, node: Node) =>
ownedName === "eth" ? label : node;
export const makeRegistrationId = (registrarName: string, labelHash: Labelhash, node: Node) =>
registrarName === "eth" ? labelHash : node;
24 changes: 1 addition & 23 deletions apps/ensnode/src/lib/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import type { Hex } from "viem";

/**
* An owned name for a plugin. Must end with `eth`.
*
Expand All @@ -8,24 +6,4 @@ import type { Hex } from "viem";
* owned name of `eth`, while a plugin that handles `base.eth` subnames will
* have an owned name of `base.eth`.
*/
export type OwnedName = `${string}eth`;

/**
* A hash value that uniquely identifies a single ENS name.
* Result of `namehash` function as specified in ENSIP-1.
*
* @example
* ```
* namehash("vitalik.eth") === "0xee6c4522aab0003e8d14cd40a6af439055fd2577951148c14b6cea9a53475835"
* ```
* @link https://docs.ens.domains/ensip/1#namehash-algorithm
*/
export type Node = Hex;

/**
* A hash value that identifies only a single part or "label" of an ENS name.
* The labelhash is just the Keccak-256 output for the label.
*
* @link https://docs.ens.domains/ensip/1#labelhash-algorithm
*/
export type Labelhash = Hex;
export type OwnedName = string;
4 changes: 2 additions & 2 deletions apps/ensnode/test/ids.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ describe("ids", () => {
});

describe("makeRegistrationId", () => {
it("should use label when ownedName is exactly `eth` to ensure subgraph compatibility", () => {
it("should use labelhash when ownedName is `eth` to ensure subgraph compatibility", () => {
expect(makeRegistrationId("eth", labelhash("vitalik"), namehash("vitalik.eth"))).toEqual(
labelhash("vitalik"),
);
});

it("should use node when ownedName is not exactly `eth`", () => {
it("should use node when ownedName is not `eth`", () => {
expect(
makeRegistrationId("linea.eth", labelhash("vitalik"), namehash("vitalik.linea.eth")),
).toEqual(namehash("vitalik.linea.eth"));
Expand Down
3 changes: 2 additions & 1 deletion packages/ensnode-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"./helpers": "./src/helpers.ts",
"./ids": "./src/ids.ts",
"./plugin-helpers": "./src/plugin-helpers.ts",
"./subname-helpers": "./src/subname-helpers.ts"
"./subname-helpers": "./src/subname-helpers.ts",
"./types": "./src/types.ts"
},
"scripts": {
"lint": "biome check --write .",
Expand Down
21 changes: 21 additions & 0 deletions packages/ensnode-utils/src/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import type { Hex } from "viem";

/**
* A hash value that uniquely identifies a single ENS name.
* Result of `namehash` function as specified in ENSIP-1.
*
* @example
* ```
* namehash("vitalik.eth") === "0xee6c4522aab0003e8d14cd40a6af439055fd2577951148c14b6cea9a53475835"
* ```
* @link https://docs.ens.domains/ensip/1#namehash-algorithm
*/
export type Node = Hex;

/**
* A hash value that identifies only a single part or "label" of an ENS name.
* The labelhash is just the Keccak-256 output for the label.
*
* @link https://docs.ens.domains/ensip/1#labelhash-algorithm
*/
export type Labelhash = Hex;

0 comments on commit 0386066

Please sign in to comment.