@ensdomains/ensjs 3.0.0-alpha.36 → 3.0.0-alpha.37

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.
@@ -33,7 +33,8 @@ __export(initialGetters_exports, {
33
33
  getPrice: () => import_getPrice.default,
34
34
  getProfile: () => import_getProfile.default,
35
35
  getRecords: () => import_getRecords.default,
36
- getSubnames: () => import_getSubnames.default
36
+ getSubnames: () => import_getSubnames.default,
37
+ supportsTLD: () => import_supportsTLD.default
37
38
  });
38
39
  module.exports = __toCommonJS(initialGetters_exports);
39
40
  var import_batch = __toESM(require("./batch"));
@@ -47,3 +48,4 @@ var import_getProfile = __toESM(require("./getProfile"));
47
48
  var import_getRecords = __toESM(require("./getRecords"));
48
49
  __reExport(initialGetters_exports, require("./getSpecificRecord"), module.exports);
49
50
  var import_getSubnames = __toESM(require("./getSubnames"));
51
+ var import_supportsTLD = __toESM(require("./supportsTLD"));
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var supportsTLD_exports = {};
20
+ __export(supportsTLD_exports, {
21
+ default: () => supportsTLD_default
22
+ });
23
+ module.exports = __toCommonJS(supportsTLD_exports);
24
+ var import_DNSRegistrar_factory = require("../generated/factories/DNSRegistrar__factory");
25
+ const DNSSEC_CLAIM_INTERFACE_IDS = ["0x2f435428", "0x17d8f49b", "0x1aa2e641"];
26
+ async function supportsTLD_default({ getOwner, provider }, name) {
27
+ try {
28
+ const labels = name.split(".");
29
+ const tld = labels[labels.length - 1];
30
+ if (tld === "eth")
31
+ return true;
32
+ const tldOwner = await getOwner(tld, "registry");
33
+ if (!tldOwner?.owner)
34
+ return false;
35
+ const dnsRegistrar = import_DNSRegistrar_factory.DNSRegistrar__factory.connect(
36
+ tldOwner.owner,
37
+ provider
38
+ );
39
+ const supports = await Promise.all(
40
+ DNSSEC_CLAIM_INTERFACE_IDS.map(
41
+ (interfaceId) => dnsRegistrar.supportsInterface(interfaceId)
42
+ )
43
+ );
44
+ return supports.some((s) => !!s);
45
+ } catch {
46
+ return false;
47
+ }
48
+ }
package/dist/cjs/index.js CHANGED
@@ -261,6 +261,11 @@ class ENS {
261
261
  "getDNSOwner",
262
262
  []
263
263
  );
264
+ supportsTLD = this.generateFunction(
265
+ "initialGetters",
266
+ ["getOwner", "provider"],
267
+ "supportsTLD"
268
+ );
264
269
  getAvailable = this.generateRawFunction(
265
270
  "getAvailable",
266
271
  ["contracts"]
@@ -10,6 +10,7 @@ import { default as default8 } from "./getProfile.mjs";
10
10
  import { default as default9 } from "./getRecords.mjs";
11
11
  export * from "./getSpecificRecord.mjs";
12
12
  import { default as default10 } from "./getSubnames.mjs";
13
+ import { default as default11 } from "./supportsTLD.mjs";
13
14
  export {
14
15
  default2 as batch,
15
16
  default3 as getExpiry,
@@ -19,5 +20,6 @@ export {
19
20
  default7 as getPrice,
20
21
  default8 as getProfile,
21
22
  default9 as getRecords,
22
- default10 as getSubnames
23
+ default10 as getSubnames,
24
+ default11 as supportsTLD
23
25
  };
@@ -0,0 +1,29 @@
1
+ // src/functions/supportsTLD.ts
2
+ import { DNSRegistrar__factory } from "../generated/factories/DNSRegistrar__factory.mjs";
3
+ var DNSSEC_CLAIM_INTERFACE_IDS = ["0x2f435428", "0x17d8f49b", "0x1aa2e641"];
4
+ async function supportsTLD_default({ getOwner, provider }, name) {
5
+ try {
6
+ const labels = name.split(".");
7
+ const tld = labels[labels.length - 1];
8
+ if (tld === "eth")
9
+ return true;
10
+ const tldOwner = await getOwner(tld, "registry");
11
+ if (!tldOwner?.owner)
12
+ return false;
13
+ const dnsRegistrar = DNSRegistrar__factory.connect(
14
+ tldOwner.owner,
15
+ provider
16
+ );
17
+ const supports = await Promise.all(
18
+ DNSSEC_CLAIM_INTERFACE_IDS.map(
19
+ (interfaceId) => dnsRegistrar.supportsInterface(interfaceId)
20
+ )
21
+ );
22
+ return supports.some((s) => !!s);
23
+ } catch {
24
+ return false;
25
+ }
26
+ }
27
+ export {
28
+ supportsTLD_default as default
29
+ };
@@ -233,6 +233,11 @@ var ENS = class {
233
233
  "getDNSOwner",
234
234
  []
235
235
  );
236
+ supportsTLD = this.generateFunction(
237
+ "initialGetters",
238
+ ["getOwner", "provider"],
239
+ "supportsTLD"
240
+ );
236
241
  getAvailable = this.generateRawFunction(
237
242
  "getAvailable",
238
243
  ["contracts"]
@@ -9,3 +9,4 @@ export { default as getProfile } from './getProfile';
9
9
  export { default as getRecords } from './getRecords';
10
10
  export * from './getSpecificRecord';
11
11
  export { default as getSubnames } from './getSubnames';
12
+ export { default as supportsTLD } from './supportsTLD';
@@ -0,0 +1,2 @@
1
+ import { ENSArgs } from '..';
2
+ export default function ({ getOwner, provider }: ENSArgs<'getOwner' | 'provider'>, name: string): Promise<boolean>;
@@ -356,7 +356,11 @@ export declare class ENS {
356
356
  registrant?: string | undefined;
357
357
  owner?: string | undefined;
358
358
  ownershipLevel: "nameWrapper" | "registrar" | "registry";
359
- } | undefined>;
359
+ } | undefined>; /**
360
+ * Creates an object of ENS properties from an array
361
+ * @param {FunctionDeps} dependencies - An array of ENS properties
362
+ * @returns {Object} - An object of ENS properties
363
+ */
360
364
  }>;
361
365
  getExpiry: GeneratedRawFunction<{
362
366
  raw: (ensArgs: ENSArgs<"contracts" | "multicallWrapper">, name: string, { contract }?: {
@@ -429,6 +433,7 @@ export declare class ENS {
429
433
  } | undefined>;
430
434
  }>;
431
435
  getDNSOwner: (dnsName: string) => Promise<any>;
436
+ supportsTLD: (name: string) => Promise<boolean>;
432
437
  getAvailable: GeneratedRawFunction<{
433
438
  raw: ({ contracts }: ENSArgs<"contracts">, name: string) => Promise<{
434
439
  to: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ensdomains/ensjs",
3
- "version": "3.0.0-alpha.36",
3
+ "version": "3.0.0-alpha.37",
4
4
  "description": "ENS javascript library for contract interaction",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "module": "./dist/esm/index.mjs",
@@ -9,3 +9,4 @@ export { default as getProfile } from './getProfile'
9
9
  export { default as getRecords } from './getRecords'
10
10
  export * from './getSpecificRecord'
11
11
  export { default as getSubnames } from './getSubnames'
12
+ export { default as supportsTLD } from './supportsTLD'
@@ -0,0 +1,45 @@
1
+ import { ENS } from '..'
2
+ import setup from '../tests/setup'
3
+
4
+ let ensInstance: ENS
5
+ let revert: Awaited<ReturnType<typeof setup>>['revert']
6
+
7
+ beforeAll(async () => {
8
+ ;({ ensInstance, revert } = await setup())
9
+ })
10
+
11
+ afterAll(async () => {
12
+ await revert()
13
+ })
14
+
15
+ describe('supportsTLD', () => {
16
+ it('should return true for .eth tld', async () => {
17
+ const result = await ensInstance.supportsTLD('eth')
18
+ expect(result).toBeTruthy()
19
+ })
20
+
21
+ it('should return true for .xyz tld', async () => {
22
+ const result = await ensInstance.supportsTLD('xyz')
23
+ expect(result).toBeTruthy()
24
+ })
25
+
26
+ it('should return false for .com tld', async () => {
27
+ const result = await ensInstance.supportsTLD('com')
28
+ expect(result).toBeFalsy()
29
+ })
30
+
31
+ it('should return true for .eth name', async () => {
32
+ const result = await ensInstance.supportsTLD('test123.eth')
33
+ expect(result).toBeTruthy()
34
+ })
35
+
36
+ it('should return true for .xyz name', async () => {
37
+ const result = await ensInstance.supportsTLD('test123.xyz')
38
+ expect(result).toBeTruthy()
39
+ })
40
+
41
+ it('should return false for .com name', async () => {
42
+ const result = await ensInstance.supportsTLD('test123.com')
43
+ expect(result).toBeFalsy()
44
+ })
45
+ })
@@ -0,0 +1,38 @@
1
+ import { DNSRegistrar__factory } from '../generated/factories/DNSRegistrar__factory'
2
+ import { ENSArgs } from '..'
3
+
4
+ /*
5
+ * 0x2f435428 -> interfaceId for latest IDNSRegistrar
6
+ * 0x17d8f49b, 0x1aa2e641 -> interfaceId for claims method of older DNSRegistrar
7
+ * */
8
+ const DNSSEC_CLAIM_INTERFACE_IDS = ['0x2f435428', '0x17d8f49b', '0x1aa2e641']
9
+
10
+ export default async function (
11
+ { getOwner, provider }: ENSArgs<'getOwner' | 'provider'>,
12
+ name: string,
13
+ ): Promise<boolean> {
14
+ try {
15
+ const labels = name.split('.')
16
+ const tld = labels[labels.length - 1]
17
+
18
+ if (tld === 'eth') return true
19
+
20
+ const tldOwner = await getOwner(tld, 'registry')
21
+ if (!tldOwner?.owner) return false
22
+
23
+ const dnsRegistrar = DNSRegistrar__factory.connect(
24
+ tldOwner.owner,
25
+ provider!,
26
+ )
27
+
28
+ const supports = await Promise.all(
29
+ DNSSEC_CLAIM_INTERFACE_IDS.map((interfaceId) =>
30
+ dnsRegistrar.supportsInterface(interfaceId),
31
+ ),
32
+ )
33
+
34
+ return supports.some((s) => !!s)
35
+ } catch {
36
+ return false
37
+ }
38
+ }
package/src/index.ts CHANGED
@@ -15,6 +15,7 @@ import type createSubname from './functions/createSubname'
15
15
  import type deleteSubname from './functions/deleteSubname'
16
16
  import type getAvailable from './functions/getAvailable'
17
17
  import type getDNSOwner from './functions/getDNSOwner'
18
+ import type supportsTLD from './functions/supportsTLD'
18
19
  import type getExpiry from './functions/getExpiry'
19
20
  import type { getHistory } from './functions/getHistory'
20
21
  import type getName from './functions/getName'
@@ -548,6 +549,12 @@ export class ENS {
548
549
  [],
549
550
  )
550
551
 
552
+ public supportsTLD = this.generateFunction<typeof supportsTLD>(
553
+ 'initialGetters',
554
+ ['getOwner', 'provider'],
555
+ 'supportsTLD',
556
+ )
557
+
551
558
  public getAvailable = this.generateRawFunction<typeof getAvailable>(
552
559
  'getAvailable',
553
560
  ['contracts'],