enssdk 0.0.1 → 1.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,619 @@
1
+ import { H as Hex, A as Address, N as NormalizedAddress, a as AccountId, b as AccountIdString, c as AssetId, d as AssetIdString, C as ChainId, e as Node, I as InterpretedName, D as DNSEncodedLiteralName, L as LiteralLabel, f as DNSEncodedName, E as ENSv1DomainId, S as StorageId, g as ENSv2DomainId, P as PermissionsId, h as PermissionsResourceId, i as PermissionsUserId, j as DomainId, R as RegistrationId, k as RegistryId, l as RenewalId, m as ResolverId, n as ResolverRecordsId, T as TokenId, o as LabelHash, p as Label, q as InterpretedLabel, r as Name, s as LiteralName, t as LabelHashPath, u as EncodedLabelHash } from './evm-2UZlELOe.js';
2
+ export { v as AssetNamespace, w as AssetNamespaces, x as CanonicalPath, y as ChainIdString, z as DNSEncodedPartiallyInterpretedName, B as DatetimeISO8601, F as DefaultableChainId, G as Duration, J as DurationBigInt, K as SubgraphInterpretedLabel, M as SubgraphInterpretedName, U as UnixTimestamp, O as UnixTimestampBigInt, Q as UrlString, W as Wei } from './evm-2UZlELOe.js';
3
+ import { EvmCoinType, CoinType } from '@ensdomains/address-encoder';
4
+ export { CoinType, EvmCoinType } from '@ensdomains/address-encoder';
5
+ import 'viem';
6
+
7
+ /**
8
+ * Describes an EnhancedAccessControl (EAC) Resource.
9
+ *
10
+ * @see https://github.com/ensdomains/contracts-v2/blob/e8696c6787e2e7a2fc17c67a3b06955a6b890adc/contracts/src/access-control/EnhancedAccessControl.sol#L17
11
+ */
12
+ type EACResource = bigint;
13
+ /**
14
+ * Describes an EnhancedAccessControl (EAC) Role Bitmap.
15
+ *
16
+ * @see https://github.com/ensdomains/contracts-v2/blob/e8696c6787e2e7a2fc17c67a3b06955a6b890adc/contracts/src/access-control/EnhancedAccessControl.sol#L33
17
+ */
18
+ type EACRoleBitmap = bigint;
19
+
20
+ /**
21
+ * ABI content type per ENSIP-4.
22
+ *
23
+ * Single-bit values (1=JSON, 2=zlib-JSON, 4=CBOR, 8=URI) identify a stored ABI encoding.
24
+ * `setABI` requires a power-of-2 value.
25
+ *
26
+ * Bitmask unions of those bits are used when reading via `ABI(node, contentTypes)`; the
27
+ * resolver returns the first stored ABI whose bit is present in the mask (lowest bit first).
28
+ *
29
+ * @see https://github.com/ensdomains/ens-contracts/blob/91c966febd7b55494269df830fc6775f040b927b/contracts/resolvers/profiles/ABIResolver.sol
30
+ */
31
+ type ContentType = bigint;
32
+ /**
33
+ * ERC-165 4-byte interface selector.
34
+ *
35
+ * @see https://github.com/ensdomains/ens-contracts/blob/91c966febd7b55494269df830fc6775f040b927b/contracts/resolvers/profiles/InterfaceResolver.sol
36
+ */
37
+ type InterfaceId = Hex;
38
+ /**
39
+ * IVersionableResolver record version. Bumped by `VersionChanged`, which invalidates all prior
40
+ * records for the node.
41
+ *
42
+ * @see https://github.com/ensdomains/ens-contracts/blob/91c966febd7b55494269df830fc6775f040b927b/contracts/resolvers/profiles/IVersionableResolver.sol
43
+ */
44
+ type RecordVersion = bigint;
45
+
46
+ /**
47
+ * Determines whether an {@link Address} is a {@link NormalizedAddress}.
48
+ */
49
+ declare function isNormalizedAddress(maybeAddress: string): maybeAddress is NormalizedAddress;
50
+ /**
51
+ * Converts an {@link Address} to a {@link NormalizedAddress}.
52
+ *
53
+ * @throws if `address` does not represent an EVM Address
54
+ */
55
+ declare function toNormalizedAddress(maybeAddress: string): NormalizedAddress;
56
+ /**
57
+ * Validates that an {@link Address} is already a {@link NormalizedAddress}.
58
+ *
59
+ * @throws if the address is not already normalized
60
+ */
61
+ declare function asNormalizedAddress(address: Address): NormalizedAddress;
62
+
63
+ /**
64
+ * Stringify an {@link AccountId} as a fully lowercase CAIP-10 AccountId string.
65
+ *
66
+ * @see https://chainagnostic.org/CAIPs/caip-10
67
+ */
68
+ declare function stringifyAccountId({ chainId, address }: AccountId): AccountIdString;
69
+ /**
70
+ * Stringify an {@link AssetId} as a fully lowercase CAIP-19 AssetId string.
71
+ *
72
+ * @see https://chainagnostic.org/CAIPs/caip-19
73
+ */
74
+ declare function stringifyAssetId({ assetNamespace, contract: { chainId, address }, tokenId, }: AssetId): AssetIdString;
75
+
76
+ /**
77
+ * The ETH coinType.
78
+ *
79
+ * @see https://docs.ens.domains/ensip/9
80
+ */
81
+ declare const ETH_COIN_TYPE: CoinType;
82
+ /**
83
+ * The 'default' chainId corresponding to the below {@link DEFAULT_EVM_COIN_TYPE} in the context of
84
+ * ENSIP-19.
85
+ *
86
+ * @see https://docs.ens.domains/ensip/19
87
+ */
88
+ declare const DEFAULT_EVM_CHAIN_ID = 0;
89
+ /**
90
+ * ENSIP-19 EVM CoinType representing the 'default' coinType for EVM chains in ENS.
91
+ *
92
+ * @see https://docs.ens.domains/ensip/19/#reverse-resolution
93
+ */
94
+ declare const DEFAULT_EVM_COIN_TYPE: EvmCoinType;
95
+ /**
96
+ * Converts a CoinType to an EVM Chain Id.
97
+ *
98
+ * NOTE: for whatever reason @ensdomains/address-encoder#coinTypeToEvmChainId doesn't handle the
99
+ * mainnet case so we implement that here
100
+ *
101
+ * @see https://docs.ens.domains/ensip/11
102
+ */
103
+ declare const coinTypeToEvmChainId: (coinType: CoinType) => ChainId;
104
+ /**
105
+ * Converts an EVM Chain Id to a CoinType.
106
+ *
107
+ * NOTE: for whatever reason @ensdomains/address-encoder#evmChainIdToCoinType doesn't handle the
108
+ * mainnet case so we implement that here
109
+ */
110
+ declare const evmChainIdToCoinType: (chainId: ChainId) => CoinType;
111
+ /**
112
+ * Converts a bigint value representing a CoinType into a valid CoinType.
113
+ *
114
+ * This is useful when onchain events emit coinTypes as bigint but we want to constrain them to
115
+ * the CoinType type.
116
+ *
117
+ * @throws if `value` is too large to fit in Number.MAX_SAFE_INTEGER
118
+ */
119
+ declare const bigintToCoinType: (value: bigint) => CoinType;
120
+
121
+ /**
122
+ * Name for the ENS Root
123
+ *
124
+ * @dev manually cast to InterpretedName to avoid circular import
125
+ */
126
+ declare const ENS_ROOT_NAME: InterpretedName;
127
+ /**
128
+ * The {@link Node} that identifies the ENS Root Name ("").
129
+ */
130
+ declare const ENS_ROOT_NODE: Node;
131
+ /**
132
+ * The {@link Node} that identifies the ETH Name ("eth").
133
+ *
134
+ * @dev manually cast to InterpretedName to avoid circular import
135
+ */
136
+ declare const ETH_NODE: Node;
137
+ /**
138
+ * The {@link Node} that identifies the addr.reverse Name ("addr.reverse").
139
+ *
140
+ * @dev manually cast to InterpretedName to avoid circular import
141
+ */
142
+ declare const ADDR_REVERSE_NODE: Node;
143
+ /**
144
+ * ROOT_RESOURCE represents the 'root' resource in an EnhancedAccessControl contract.
145
+ */
146
+ declare const ROOT_RESOURCE: EACResource;
147
+
148
+ /**
149
+ * Decodes a DNS-Encoded name consisting of Literal Labels into an ordered list of Literal Labels.
150
+ *
151
+ * For discussion on DNS-Encoding, see the {@link DNSEncodedName} and {@link DNSEncodedLiteralName} types.
152
+ *
153
+ * Due to the constraints of DNS-Encoding, there is an additional guarantee that each Literal Label
154
+ * in the resulting list is guaranteed to have a maximum byte length of 255.
155
+ *
156
+ * @param packet a hex string that encodes a DNSEncodedLiteralName
157
+ * @returns A list of the LiteralLabels contained in packet
158
+ * @throws If the packet is malformed
159
+ * @dev This is just `decodeDNSEncodedName` with semantic input/output
160
+ */
161
+ declare function decodeDNSEncodedLiteralName(packet: DNSEncodedLiteralName): LiteralLabel[];
162
+ /**
163
+ * Decodes a DNS-Encoded Name into an ordered list of string segments.
164
+ *
165
+ * For discussion on DNS-Encoding, see the {@link DNSEncodedName} type.
166
+ *
167
+ * Due to the constraints of DNS-Encoding, there is an additional guarantee that each segment
168
+ * in the resulting list is guaranteed to have a maximum byte length of 255.
169
+ *
170
+ * @param packet a hex string that encodes a DNSEncodedName
171
+ * @returns A UTF-8 string array of the segments contained in packet
172
+ * @throws If the packet is malformed
173
+ * @dev This is the generic implementation of DNS-Encoded Name Decoding
174
+ */
175
+ declare function decodeDNSEncodedName(packet: DNSEncodedName): string[];
176
+
177
+ declare const makeRegistryId: (accountId: AccountId) => RegistryId;
178
+ declare const makeResolverId: (contract: AccountId) => ResolverId;
179
+ declare const makeENSv1DomainId: (node: Node) => ENSv1DomainId;
180
+ declare const makeENSv2DomainId: (registry: AccountId, storageId: StorageId) => ENSv2DomainId;
181
+ /**
182
+ * Computes a Label's {@link StorageId} given its TokenId or LabelHash.
183
+ */
184
+ declare const makeStorageId: (labelRef: TokenId | LabelHash) => StorageId;
185
+ declare const makePermissionsId: (contract: AccountId) => PermissionsId;
186
+ declare const makePermissionsResourceId: (contract: AccountId, resource: EACResource) => PermissionsResourceId;
187
+ declare const makePermissionsUserId: (contract: AccountId, resource: EACResource, user: NormalizedAddress) => PermissionsUserId;
188
+ declare const makeResolverRecordsId: (resolver: AccountId, node: Node) => ResolverRecordsId;
189
+ declare const makeRegistrationId: (domainId: DomainId, registrationIndex: number) => RegistrationId;
190
+ declare const makeRenewalId: (domainId: DomainId, registrationIndex: number, index: number) => RenewalId;
191
+
192
+ /**
193
+ * Whether `maybeInterfaceId` is a valid ERC-165 {@link InterfaceId} — a 4-byte hex selector.
194
+ */
195
+ declare function isInterfaceId(maybeInterfaceId: string): maybeInterfaceId is InterfaceId;
196
+
197
+ /**
198
+ * Decodes a uint256-encoded-LabelHash (eg. from a {@link TokenId}) into a {@link LabelHash}.
199
+ *
200
+ * @see https://github.com/ensdomains/ens-contracts/blob/db613bc/contracts/ethregistrar/ETHRegistrarController.sol#L215
201
+ */
202
+ declare const interpretTokenIdAsLabelHash: (tokenId: TokenId) => LabelHash;
203
+ /**
204
+ * Decodes a uint256-encoded-Node (eg. from a {@link TokenId}) into a {@link Node}.
205
+ *
206
+ * @see https://github.com/ensdomains/ens-contracts/blob/db613bc/contracts/wrapper/ERC1155Fuse.sol#L262
207
+ */
208
+ declare const interpretTokenIdAsNode: (tokenId: TokenId) => Node;
209
+
210
+ /**
211
+ * Interprets a user-provided {@link LiteralName} as an {@link InterpretedName}.
212
+ *
213
+ * A {@link LiteralName} may be any arbitrary string. The ENS Root Name ('') ({@link ENS_ROOT_NAME})
214
+ * is only accepted when `options.allowENSRootName` is `true`, and is returned as-is.
215
+ *
216
+ * This function walks each LiteralLabel of `name` and maps it to an {@link InterpretedLabel}
217
+ * according to the provided `options`:
218
+ *
219
+ * 0. If the LiteralLabel is an empty string (''), this function throws: an empty Label is not a valid
220
+ * {@link InterpretedLabel}.
221
+ * 1. If the LiteralLabel is already a normalized LiteralLabel, it is kept as-is.
222
+ * 2. Otherwise, if the LiteralLabel looks like an {@link EncodedLabelHash} (e.g. `[abcd…]`) and
223
+ * `options.allowEncodedLabelHashes` is `true`, it is kept as-is.
224
+ * 3. Otherwise, the LiteralLabel is unnormalized. If `options.coerceUnnormalizedLabelsToNormalizedLabels` is `false`,
225
+ * this function throws. Otherwise (default), the LiteralLabel is passed through ENSIP-15 normalization
226
+ * ({@link normalizeLabel}). If normalization succeeds, the normalized form is used (e.g. `"Vitalik"` →
227
+ * `"vitalik"`).
228
+ * 4. Otherwise, the LiteralLabel is unnormalizable. If `options.coerceUnnormalizableLabelsToEncodedLabelHashes`
229
+ * is `true`, the Label is replaced with the EncodedLabelHash of its literal bytes. Otherwise, this
230
+ * function throws.
231
+ *
232
+ * Note that step 3 gates step 4: if `options.coerceUnnormalizedLabelsToNormalizedLabels` is `false`, the
233
+ * function throws immediately for any unnormalized Label, regardless of whether the Label would have been
234
+ * normalizable and regardless of `options.coerceUnnormalizableLabelsToEncodedLabelHashes`.
235
+ *
236
+ * @param name - The user-provided {@link LiteralName} to interpret.
237
+ * @param options - Controls how the interpretation handles edge cases.
238
+ * @param options.allowENSRootName - When `true`, an empty `name` is accepted and returned as the ENS Root Name.
239
+ * When `false` (default), an empty `name` throws.
240
+ * @param options.allowEncodedLabelHashes - When `true`, a Label that is already formatted as an
241
+ * {@link EncodedLabelHash} is preserved verbatim. When `false` (default), such a Label is treated like any other
242
+ * input and passed through normalization, which will fail and fall through to the unnormalizable-Label handling.
243
+ * @param options.coerceUnnormalizedLabelsToNormalizedLabels - When `true` (default), a Label that is not already
244
+ * normalized is passed through ENSIP-15 normalization (e.g. `"Vitalik"` → `"vitalik"`). When `false`, any
245
+ * unnormalized Label causes this function to throw — no normalization is attempted and
246
+ * `coerceUnnormalizableLabelsToEncodedLabelHashes` is not consulted.
247
+ * @param options.coerceUnnormalizableLabelsToEncodedLabelHashes - When `true`, a Label that cannot be normalized is
248
+ * replaced with the EncodedLabelHash of its literal bytes. When `false` (default), encountering such a Label causes
249
+ * this function to throw. Only consulted when `coerceUnnormalizedLabelsToNormalizedLabels` is `true`.
250
+ *
251
+ * @throws if `name` cannot be coerced into an {@link InterpretedName} under the provided `options`.
252
+ *
253
+ * @dev casts to {@link InterpretedLabel} to avoid an additional unnecessary `asInterpretedLabel` pass.
254
+ */
255
+ declare function literalNameToInterpretedName(name: LiteralName, { allowENSRootName, allowEncodedLabelHashes, coerceUnnormalizedLabelsToNormalizedLabels, coerceUnnormalizableLabelsToEncodedLabelHashes, }?: {
256
+ allowENSRootName?: boolean | undefined;
257
+ allowEncodedLabelHashes?: boolean | undefined;
258
+ coerceUnnormalizedLabelsToNormalizedLabels?: boolean | undefined;
259
+ coerceUnnormalizableLabelsToEncodedLabelHashes?: boolean | undefined;
260
+ }): InterpretedName;
261
+ /**
262
+ * Interprets a Literal Label, producing an Interpreted Label.
263
+ *
264
+ * @see https://ensnode.io/docs/reference/terminology#literal-label
265
+ * @see https://ensnode.io/docs/reference/terminology#interpreted-label
266
+ *
267
+ * @param label - The Literal Label string to interpret
268
+ * @returns The provided label if it is a normalized label, else the EncodedLabelHash of the label
269
+ */
270
+ declare function literalLabelToInterpretedLabel(label: LiteralLabel): InterpretedLabel;
271
+ /**
272
+ * Interprets an ordered list of Literal Labels, producing an Interpreted Name.
273
+ *
274
+ * Note that it's important that the Literal Labels are provided as an array, otherwise it's
275
+ * impossible to differentiate between 'a.label.eth' being ['a.label', 'eth'] or ['a', 'label', 'eth'].
276
+ *
277
+ * Note that the input is an ordered list of _Literal_ Labels: in this context, any literal label
278
+ * that is formatted as an Encoded LabelHash will NOT be interpreted as such. Instead it will be
279
+ * interpreted into an Encoded LabelHash that encodes the literal labelhash of the Literal Label.
280
+ *
281
+ * @param labels An ordered list of 0 or more Literal Labels
282
+ * @returns An InterpretedName
283
+ */
284
+ declare function literalLabelsToInterpretedName(labels: LiteralLabel[]): InterpretedName;
285
+ /**
286
+ * Joins the list of Interpreted Labels with '.' to form an Interpreted Name.
287
+ *
288
+ * @param labels An ordered list of 0 or more Interpreted Labels
289
+ * @returns An InterpretedName
290
+ */
291
+ declare function interpretedLabelsToInterpretedName(labels: InterpretedLabel[]): InterpretedName;
292
+ /**
293
+ * Joins the list of Literal Labels with '.' to form a Literal Name.
294
+ *
295
+ * Note: LiteralLabel values may contain '.' characters, which will be preserved
296
+ * in the resulting LiteralName. Therefore, the number of labels in the returned
297
+ * LiteralName may be greater than the number of LiteralLabels in the input array.
298
+ *
299
+ * @param labels An ordered list of 0 or more Literal Labels
300
+ * @returns An LiteralName
301
+ */
302
+ declare function literalLabelsToLiteralName(labels: LiteralLabel[]): LiteralName;
303
+ /**
304
+ * Converts an LiteralName into a list of LiteralLabels.
305
+ */
306
+ declare function literalNameToLiteralLabels(name: LiteralName): LiteralLabel[];
307
+ /**
308
+ * Converts an Interpreted Name into a list of Interpreted Labels.
309
+ */
310
+ declare function interpretedNameToInterpretedLabels(name: InterpretedName): InterpretedLabel[];
311
+ declare function isInterpretedLabel(label: Label): label is InterpretedLabel;
312
+ /**
313
+ * Determines whether `name` is an {@link InterpretedName}.
314
+ * The root name ("") is a valid InterpretedName.
315
+ *
316
+ * @param name
317
+ * @returns
318
+ */
319
+ declare function isInterpretedName(name: Name): name is InterpretedName;
320
+ /**
321
+ * Converts InterpretedLabels into a LabelHashPath.
322
+ */
323
+ declare function interpretedLabelsToLabelHashPath(labels: InterpretedLabel[]): LabelHashPath;
324
+ /**
325
+ * Constructs a new InterpretedName from an InterpretedLabel (child) and InterpretedName (parent).
326
+ *
327
+ * If no parent is available the InterpretedLabel is cast to an InterpretedName and returned.
328
+ *
329
+ * @dev the following is safe due to InterpretedLabel/InterpretedName semantics, see above.
330
+ */
331
+ declare function constructSubInterpretedName(label: InterpretedLabel, name: InterpretedName | undefined): InterpretedName;
332
+ /**
333
+ * Given a `labelHash` and optionally its healed InterpretedLabel, return an InterpretedLabel.
334
+ */
335
+ declare function ensureInterpretedLabel(labelHash: LabelHash, label: InterpretedLabel | undefined): InterpretedLabel;
336
+ /**
337
+ * Parses a Partial InterpretedName into concrete InterpretedLabels and the partial Label.
338
+ *
339
+ * @example
340
+ * ```ts
341
+ * const result = parsePartialInterpretedName("example.et")
342
+ * // { concrete: ["example"], partial: "et" }
343
+ * ```
344
+ *
345
+ * @throws if the provided `partialInterpretedName` is not composed of concrete InterpretedLabels.
346
+ */
347
+ declare function parsePartialInterpretedName(partialInterpretedName: Name): {
348
+ concrete: InterpretedLabel[];
349
+ partial: string;
350
+ };
351
+ /**
352
+ * Casts a string to a {@link LiteralName}.
353
+ *
354
+ * A LiteralName is a name that should be interpreted as a string literal. It may or may not be
355
+ * normalized or normalizable. It may also include labels formatted as an EncodedLabelHash, but
356
+ * such labels must be interpreted literally and not as an EncodedLabelHash.
357
+ */
358
+ declare function asLiteralName(name: Name): LiteralName;
359
+ /**
360
+ * Casts a string to a {@link LiteralLabel}.
361
+ *
362
+ * A LiteralLabel is a label that should be interpreted as a string literal. It may or may not be
363
+ * normalized or normalizable. It may also be formatted as an EncodedLabelHash, but such labels must
364
+ * be interpreted literally and not as an EncodedLabelHash.
365
+ */
366
+ declare function asLiteralLabel(label: Label): LiteralLabel;
367
+ /**
368
+ * Validates and casts a string to an {@link InterpretedLabel}.
369
+ * An InterpretedLabel is either a normalized label or an EncodedLabelHash.
370
+ *
371
+ * @throws if the input is not a valid InterpretedLabel
372
+ */
373
+ declare function asInterpretedLabel(label: Label): InterpretedLabel;
374
+ /**
375
+ * Validates and casts a string to an {@link InterpretedName}.
376
+ * An InterpretedName is either the ENS Root Name ('') or a name made up of InterpretedLabels (which
377
+ * are either normalized Labels or EncodedLabelHashes).
378
+ *
379
+ * @throws if the input cannot be interpreted into an InterpretedName
380
+ */
381
+ declare function asInterpretedName(name: Name): InterpretedName;
382
+
383
+ /**
384
+ * Typed wrapper around viem's `labelhash` that returns a branded {@link LabelHash},
385
+ * requiring an {@link InterpretedLabel} input.
386
+ *
387
+ * Note: viem's labelhash has special-case handling for Encoded LabelHashes (e.g. `[hash]`).
388
+ * Use {@link labelhashLiteralLabel} if you need to hash a label's literal bytes without
389
+ * encoded labelhash detection.
390
+ *
391
+ * @see https://docs.ens.domains/ensip/1
392
+ */
393
+ declare const labelhashInterpretedLabel: (label: InterpretedLabel) => LabelHash;
394
+ /**
395
+ * Implements the ENS `labelhash` function for Literal Labels.
396
+ * @see https://docs.ens.domains/ensip/1
397
+ *
398
+ * @param label the Literal Label to hash
399
+ * @returns the hash of the provided label
400
+ * @dev This function is viem/ens#labelhash but without the special-case handling of Encoded LabelHashes.
401
+ */
402
+ declare const labelhashLiteralLabel: (label: LiteralLabel) => LabelHash;
403
+ /**
404
+ * Checks if the input is a {@link LabelHash}.
405
+ *
406
+ * @see https://ensnode.io/docs/reference/terminology#label-processing-and-classification
407
+ */
408
+ declare function isLabelHash(maybeLabelHash: string): maybeLabelHash is LabelHash;
409
+ /**
410
+ * Formats a LabelHash as an Encoded LabelHash.
411
+ *
412
+ * @see https://ensnode.io/docs/reference/terminology#encoded-labelhash
413
+ *
414
+ * @param labelHash - A 32-byte lowercase hash string starting with '0x'
415
+ * @returns The encoded label hash in format `[labelhash_without_0x_prefix]`
416
+ */
417
+ declare const encodeLabelHash: (labelHash: LabelHash) => EncodedLabelHash;
418
+ /**
419
+ * Decodes an Encoded LabelHash as a LabelHash.
420
+ *
421
+ * @throws if a valid LabelHash cannot be decoded
422
+ *
423
+ * @see https://ensnode.io/docs/reference/terminology#encoded-labelhash
424
+ * @see https://github.com/wevm/viem/blob/main/src/utils/ens/encodedLabelToLabelhash.ts
425
+ *
426
+ * @param maybeEncodedLabelHash The encoded label hash in format `[labelhash_without_0x_prefix]`
427
+ * @returns A 32-byte lowercase hash string starting with '0x'
428
+ */
429
+ declare const decodeEncodedLabelHash: (maybeEncodedLabelHash: string) => LabelHash;
430
+ /**
431
+ * Checks if the value is an {@link EncodedLabelHash}.
432
+ */
433
+ declare function isEncodedLabelHash(value: string): value is EncodedLabelHash;
434
+
435
+ /**
436
+ * Typed wrapper around viem's `namehash` that returns a branded {@link Node},
437
+ * requiring an {@link InterpretedName} input and correctly parsing EncodedLabelHashes.
438
+ *
439
+ * @see https://docs.ens.domains/ensip/1
440
+ */
441
+ declare const namehashInterpretedName: (name: InterpretedName) => Node;
442
+ /**
443
+ * Implements one step of the namehash algorithm, combining `labelHash` with `node` to produce
444
+ * the `node` of a given subdomain. Note that the order of the arguments is 'reversed' (as compared to
445
+ * the actual concatenation) in order to improve readability (i.e. read as [labelHash].[node]).
446
+ */
447
+ declare const makeSubdomainNode: (labelHash: LabelHash, node: Node) => Node;
448
+
449
+ /**
450
+ * Constructs a name hierarchy from a given InterpretedName.
451
+ *
452
+ * @example
453
+ * ```
454
+ * getNameHierarchy("sub.example.eth") -> ["sub.example.eth", "example.eth", "eth"]
455
+ * ```
456
+ */
457
+ declare const getNameHierarchy: (name: InterpretedName) => InterpretedName[];
458
+ /**
459
+ * Derives the parent's {@link InterpretedName} of the provided `name`, or null if there is none.
460
+ */
461
+ declare const getParentInterpretedName: (name: InterpretedName) => InterpretedName | null;
462
+ /**
463
+ * Beautifies a name by converting each normalized label in the provided name to
464
+ * its "beautified" form. Labels that are not normalized retain their original value.
465
+ *
466
+ * Invariants:
467
+ * - The number of labels in the returned name is the same as the number of labels in the input name.
468
+ * - The order of the labels in the returned name is the same as the order of the labels in the input name.
469
+ * - If a label in the input is normalized, it is returned in its "beautified" form.
470
+ * - If a label in the input name is not normalized, it is returned without modification.
471
+ * - Therefore, the result of ens_normalize(beautifyName(name)) is the same as the result of ens_normalize(name).
472
+ *
473
+ * The "beautified form" of a normalized label converts special sequences of
474
+ * emojis and other special characters to their "beautified" equivalents. All
475
+ * such conversions transform X -> Y where Y is normalizable and normalizes back to X.
476
+ * Ex: '1⃣2⃣' (normalized) to '1️⃣2️⃣' (normalizable but not normalized).
477
+ * Ex: 'ξethereum' (normalized) to 'Ξethereum' (normalizable, but not normalized).
478
+ * Ex: 'abc' (normalized) to 'abc' (also normalized, no conversion).
479
+ * Ex: 'ABC' (normalizable but not normalized) to 'ABC' (no conversion).
480
+ * Ex: 'invalid|label' (not normalizable) to 'invalid|label' (no conversion).
481
+ * Ex: '' (unnormalized as a label) to '' (no conversion).
482
+ *
483
+ * @param name - The name to beautify.
484
+ * @returns The beautified name.
485
+ */
486
+ declare const beautifyName: (name: Name) => Name;
487
+
488
+ /**
489
+ * Normalizes a Name according to ENS normalization rules (ENSIP-15), returning an InterpretedName.
490
+ *
491
+ * @throws if the Name is not normalizable
492
+ * @see https://docs.ens.domains/ensip/15
493
+ */
494
+ declare const normalizeName: (name: Name) => InterpretedName;
495
+ /**
496
+ * Normalizes a Label according to ENS normalization rules (ENSIP-15), returning an InterpretedLabel.
497
+ *
498
+ * @throws if the Label is not normalizable
499
+ * @see https://docs.ens.domains/ensip/15
500
+ */
501
+ declare const normalizeLabel: (label: Label) => InterpretedLabel;
502
+ /**
503
+ * Determines whether the Name is normalized according to ENSIP-15 normalization rules.
504
+ */
505
+ declare function isNormalizedName(name: Name): boolean;
506
+ /**
507
+ * Determines whether the Label is normalized according to ENSIP-15 normalization rules.
508
+ */
509
+ declare function isNormalizedLabel(label: Label): boolean;
510
+
511
+ /**
512
+ * Parses a labelHash string and normalizes it to a canonical `LabelHash`.
513
+ *
514
+ * Normalization rules applied in order:
515
+ * 1. Adds `0x` prefix if missing
516
+ * 2. Validates all characters (excluding the optional `0x` prefix) are valid hex digits
517
+ * (uppercase or lowercase A-F are accepted and normalized to lowercase)
518
+ * 3. If the hex digit count is odd, adds a leading `0` to make it even
519
+ * 4. Validates the result is exactly 64 hex digits (32 bytes)
520
+ *
521
+ * @param maybeLabelHash - The string to parse as a labelHash
522
+ * @throws {Error} If the input cannot be normalized to a valid labelHash
523
+ */
524
+ declare function parseLabelHash(maybeLabelHash: string): LabelHash;
525
+ /**
526
+ * Parses an encoded labelHash string (surrounded by square brackets) and normalizes it.
527
+ *
528
+ * This function is intentionally more lenient than {@link isEncodedLabelHash}: it accepts
529
+ * both the canonical format `[hash]` (no `0x` inside brackets) and the non-canonical
530
+ * `[0xhash]` format by delegating to {@link parseLabelHash} for the inner value.
531
+ * `isEncodedLabelHash("[0xhash]")` returns `false` for the same input.
532
+ *
533
+ * @param maybeEncodedLabelHash - The string to parse as an encoded labelHash
534
+ * @throws {Error} If the input is not properly enclosed in brackets or cannot be normalized
535
+ */
536
+ declare function parseEncodedLabelHash(maybeEncodedLabelHash: string): LabelHash;
537
+ /**
538
+ * Parses a labelHash or encoded labelHash string and normalizes it.
539
+ *
540
+ * Tries both formats to be maximally generous with accepted inputs:
541
+ * - If the input starts with `[` and ends with `]`, it is treated as an encoded labelHash
542
+ * - Otherwise, it is treated as a plain labelHash
543
+ *
544
+ * @param maybeLabelHash - The string to parse as a labelHash or encoded labelHash
545
+ * @throws {Error} If the input cannot be normalized to a valid labelHash
546
+ */
547
+ declare function parseLabelHashOrEncodedLabelHash(maybeLabelHash: string): LabelHash;
548
+
549
+ /**
550
+ * Parse the address and coinType out of an ENSIP-19 reverse name.
551
+ */
552
+ declare function parseReverseName(name: string): {
553
+ address: NormalizedAddress;
554
+ coinType: CoinType;
555
+ } | null;
556
+
557
+ /**
558
+ * Reinterpret Label
559
+ *
560
+ * Reinterprets {@link InterpretedLabel} values received by "External System"
561
+ * into {@link InterpretedLabel} values in "Internal System" where:
562
+ * 1. "External System" is not guaranteed to be using the same ENSNormalize
563
+ * version as "Internal System", and therefore the `InterpretedLabel` passed into
564
+ * this function (from "External System") is not guaranteed to 100% align
565
+ * with the invariants of an `InterpretedLabel` in "Internal System".
566
+ * 2. The `InterpretedLabel` returned by this function is guaranteed to match
567
+ * the invariants of `InterpretedLabel` in "Internal System".
568
+ *
569
+ * @returns reinterpreted label.
570
+ * @throws an error if the provided label is an empty label
571
+ * (and therefore violates the invariants of an InterpretedLabel).
572
+ */
573
+ declare function reinterpretLabel(label: InterpretedLabel): InterpretedLabel;
574
+ /**
575
+ * Reinterpret Name
576
+ *
577
+ * Reinterprets {@link InterpretedName} values received by "External System"
578
+ * into {@link InterpretedName} values in "Internal System" where:
579
+ * 1. "External System" is not guaranteed to be using the same ENSNormalize
580
+ * version as "Internal System", and therefore the `InterpretedName` passed into
581
+ * this function (from "External System") is not guaranteed to 100% align
582
+ * with the invariants of an `InterpretedName` in "Internal System".
583
+ * 2. The `InterpretedName` returned by this function is guaranteed to match
584
+ * the invariants of `InterpretedName` in "Internal System".
585
+ */
586
+ declare function reinterpretName(name: InterpretedName): InterpretedName;
587
+
588
+ /**
589
+ * Gets the Label used for the reverse names of subnames as per ENSIP-11 & ENSIP-19.
590
+ *
591
+ * @see https://docs.ens.domains/ensip/19/#reverse-resolution
592
+ */
593
+ declare const addrReverseLabel: (address: NormalizedAddress) => LiteralLabel;
594
+ /**
595
+ * Converts `coinType` to prefix-free hex string.
596
+ *
597
+ * @see https://docs.ens.domains/ensip/19
598
+ */
599
+ declare const coinTypeReverseLabel: (coinType: CoinType) => LiteralLabel;
600
+ /**
601
+ * Gets the reverse name for an address according to ENSIP-11 & ENSIP-19.
602
+ *
603
+ * @see https://docs.ens.domains/ensip/11#specification
604
+ * @see https://docs.ens.domains/ensip/19#specification
605
+ *
606
+ * @param address - The address to get the reverse name for
607
+ * @param coinType - The coin type to use for the reverse name
608
+ * @returns The reverse name for the address
609
+ *
610
+ * @example
611
+ * ```ts
612
+ * reverseName("0x1234", BigInt(ETH_COIN_TYPE)) // "1234.addr.reverse"
613
+ * reverseName("0x1234", BigInt(0x80000000)) // "1234.default.reverse"
614
+ * reverseName("0x1234", BigInt(0x5678)) // "1234.5678.reverse"
615
+ * ```
616
+ */
617
+ declare function reverseName(address: NormalizedAddress, coinType: CoinType): LiteralName;
618
+
619
+ export { ADDR_REVERSE_NODE, AccountId, AccountIdString, Address, AssetId, AssetIdString, ChainId, type ContentType, DEFAULT_EVM_CHAIN_ID, DEFAULT_EVM_COIN_TYPE, DNSEncodedLiteralName, DNSEncodedName, DomainId, type EACResource, type EACRoleBitmap, ENS_ROOT_NAME, ENS_ROOT_NODE, ENSv1DomainId, ENSv2DomainId, ETH_COIN_TYPE, ETH_NODE, EncodedLabelHash, Hex, type InterfaceId, InterpretedLabel, InterpretedName, Label, LabelHash, LabelHashPath, LiteralLabel, LiteralName, Name, Node, NormalizedAddress, PermissionsId, PermissionsResourceId, PermissionsUserId, ROOT_RESOURCE, type RecordVersion, RegistrationId, RegistryId, RenewalId, ResolverId, ResolverRecordsId, StorageId, TokenId, addrReverseLabel, asInterpretedLabel, asInterpretedName, asLiteralLabel, asLiteralName, asNormalizedAddress, beautifyName, bigintToCoinType, coinTypeReverseLabel, coinTypeToEvmChainId, constructSubInterpretedName, decodeDNSEncodedLiteralName, decodeDNSEncodedName, decodeEncodedLabelHash, encodeLabelHash, ensureInterpretedLabel, evmChainIdToCoinType, getNameHierarchy, getParentInterpretedName, interpretTokenIdAsLabelHash, interpretTokenIdAsNode, interpretedLabelsToInterpretedName, interpretedLabelsToLabelHashPath, interpretedNameToInterpretedLabels, isEncodedLabelHash, isInterfaceId, isInterpretedLabel, isInterpretedName, isLabelHash, isNormalizedAddress, isNormalizedLabel, isNormalizedName, labelhashInterpretedLabel, labelhashLiteralLabel, literalLabelToInterpretedLabel, literalLabelsToInterpretedName, literalLabelsToLiteralName, literalNameToInterpretedName, literalNameToLiteralLabels, makeENSv1DomainId, makeENSv2DomainId, makePermissionsId, makePermissionsResourceId, makePermissionsUserId, makeRegistrationId, makeRegistryId, makeRenewalId, makeResolverId, makeResolverRecordsId, makeStorageId, makeSubdomainNode, namehashInterpretedName, normalizeLabel, normalizeName, parseEncodedLabelHash, parseLabelHash, parseLabelHashOrEncodedLabelHash, parsePartialInterpretedName, parseReverseName, reinterpretLabel, reinterpretName, reverseName, stringifyAccountId, stringifyAssetId, toNormalizedAddress };