UNPKG

@ensnode/ensnode-sdk

Version:

A utility library for interacting with ENSNode and ENS data

162 lines (156 loc) 5.38 kB
import { Hex, Address } from 'viem'; /** * A PluginName is a unique id for a 'plugin': we use the notion of 'plugins' to describe bundles * of indexing logic. */ declare enum PluginName { Subgraph = "subgraph", Basenames = "basenames", Lineanames = "lineanames", ThreeDNS = "threedns" } /** * 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 */ type Node = Hex; /** * A LabelHash is the result of the labelhash function (which is just keccak256) on a Label. * * @link https://docs.ens.domains/terminology#labelhash */ type LabelHash = Hex; /** * A Label is a single part of an ENS Name. * * @link https://docs.ens.domains/terminology#label */ type Label = string; /** * An EncodedLabelHash is a specially formatted unnormalized Label that should be interpreted as a * LabelHash literal, particularly for use within an ENS Name. * * @example [abcd] * @example [abcd].example.eth */ type EncodedLabelHash = `[${string}]`; /** * A Name represents a human-readable ENS name. * * ex: vitalik.eth */ type Name = string; declare const ROOT_NODE: Node; /** * A set of nodes whose children are used for reverse resolution. * * Useful for identifying if a domain is used for reverse resolution. * See apps/ensindexer/src/handlers/Registry.ts for context. */ declare const REVERSE_ROOT_NODES: Set<Node>; /** * The ETH coinType. * * @see https://docs.ens.domains/ensip/9 */ declare const ETH_COIN_TYPE = 60n; /** * Cache that maps from string -> ValueType. */ interface Cache<KeyType extends string, ValueType> { /** * Store a value in the cache with the given key. * * @param key Cache key * @param value Value to store */ set(key: KeyType, value: ValueType): void; /** * Retrieve a value from the cache with the given key. * * @param key Cache key * @returns The cached value if it exists, otherwise undefined */ get(key: KeyType): ValueType | undefined; /** * Clear the cache. */ clear(): void; /** * The current number of items in the cache. Always a non-negative integer. */ get size(): number; /** * The maximum number of items in the cache. Always a non-negative integer that is >= size(). */ get capacity(): number; } /** * Cache that maps from string -> ValueType with a LRU (least recently used) eviction policy. * * `get` and `set` are O(1) operations. * * @link https://en.wikipedia.org/wiki/Cache_replacement_policies#LRU */ declare class LruCache<KeyType extends string, ValueType> implements Cache<KeyType, ValueType> { private readonly _cache; private readonly _capacity; /** * Create a new LRU cache with the given capacity. * * @param capacity The maximum number of items in the cache. If set to 0, the cache is effectively disabled. * @throws Error if capacity is not a non-negative integer. */ constructor(capacity: number); set(key: string, value: ValueType): void; get(key: string): ValueType | undefined; clear(): void; get size(): number; get capacity(): number; } /** * Implements one step of the namehash algorithm, combining `labelHash` with `node` to produce * the `node` of a given subdomain. Note that the order of the arguments is 'reversed' (as compared to * the actual concatenation) in order to improve readability (i.e. read as [labelHash].[node]). */ declare const makeSubdomainNode: (labelHash: LabelHash, node: Node) => Node; /** * Attempt to heal the labelHash of an addr.reverse subname using an address that might be related to the subname. * * @throws if maybeReverseAddress is not a valid Address * @throws if labelHash is not a valid Labelhash * * @returns the original label if healed, otherwise null */ declare const maybeHealLabelByReverseAddress: ({ maybeReverseAddress, labelHash, }: { /** The address that is possibly associated with the addr.reverse subname */ maybeReverseAddress: Address; /** The labelhash of the addr.reverse subname */ labelHash: LabelHash; }) => string | null; /** * Encodes a uint256 bigint as hex string sized to 32 bytes. * Uses include, in the context of ENS, decoding the uint256-encoded tokenId of NFT-issuing contracts * into Node or LabelHash, which is a common behavior in the ENS ecosystem. * (see NameWrapper, ETHRegistrarController) */ declare const uint256ToHex32: (num: bigint) => `0x${string}`; /** * Check if any characters in `label` are "unindexable". * * Related logic in ENS Subgraph: * https://github.com/ensdomains/ens-subgraph/blob/c844791/src/utils.ts#L68 * * @param label - The label to check. Note: * A `null` value for `label` represents an unhealable labelhash. * * @returns `true` if the label is indexable, `false` otherwise. */ declare const isLabelIndexable: (label: Label | null) => label is Label; export { type Cache, ETH_COIN_TYPE, type EncodedLabelHash, type Label, type LabelHash, LruCache, type Name, type Node, PluginName, REVERSE_ROOT_NODES, ROOT_NODE, isLabelIndexable, makeSubdomainNode, maybeHealLabelByReverseAddress, uint256ToHex32 };