Skip to content

Commit

Permalink
chore: tidy up comments in subname-helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
shrugs committed Jan 8, 2025
1 parent acae503 commit e25be65
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/lib/subname-helpers.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import { bytesToPacket } from "@ensdomains/ensjs/utils";
import { type Hex, concat, keccak256, namehash, toHex } from "viem";

// TODO: pull from ens utils lib or something
// NOTE: most of these utils could/should be pulled in from some (future) ens helper lib, as they
// implement standard and reusable logic for typescript ens libs bu aren't necessarily implemented
// or exposed by ensjs or viem

export const ROOT_NODE = namehash("");
export const ETH_NODE = namehash("eth");

// TODO: this should probably be a part of some ens util lib but isn't exposed by viem or ensjs
export const makeSubnodeNamehash = (node: Hex, label: Hex) => keccak256(concat([node, label]));

// converts uint256-encoded nodes to hex
export const tokenIdToLabel = (tokenId: bigint) => toHex(tokenId, { size: 32 });

// TODO: this should be part of some more standard ens helper lib
// TODO: this should be standardized via helper lib
// https://github.com/ensdomains/ens-subgraph/blob/master/src/utils.ts#L68
const INVALID_CHARACTER_CODES_IN_LABEL = new Set([0, 46, 91, 93]);
export const isLabelValid = (name: string) => {
Expand All @@ -24,14 +26,14 @@ export const isLabelValid = (name: string) => {
return true;
};

// TODO: this should be part of some more standard ens helper lib
// TODO: this should be standardized via helper lib
// https://github.com/ensdomains/ens-subgraph/blob/master/src/nameWrapper.ts#L61C1-L65C2
const PARENT_CANNOT_CONTROL = 65536;
export const checkPccBurned = (fuses: number) =>
(fuses & PARENT_CANNOT_CONTROL) == PARENT_CANNOT_CONTROL;

// TODO: this should be standardized via helper lib
// this is basically just ensjs#bytesToPacket w/ custom validity check
// TODO: this should be part of some more standard ens helper lib
// https://github.com/ensdomains/ens-subgraph/blob/master/src/nameWrapper.ts#L30
export function decodeDNSPacketBytes(buf: Uint8Array): [string | null, string | null] {
if (buf.length === 0) return ["", "."];
Expand Down

0 comments on commit e25be65

Please sign in to comment.