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

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.
Files changed (68) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +7 -0
  3. package/dist/cjs/GqlManager.js +22 -20
  4. package/dist/cjs/contracts/getContractAddress.js +1 -1
  5. package/dist/cjs/contracts/index.js +44 -46
  6. package/dist/cjs/functions/batchWrappers.js +6 -6
  7. package/dist/cjs/functions/createSubname.js +1 -1
  8. package/dist/cjs/functions/getAvailable.js +2 -2
  9. package/dist/cjs/functions/getDNSOwner.js +4 -2
  10. package/dist/cjs/functions/getExpiry.js +4 -4
  11. package/dist/cjs/functions/getName.js +2 -2
  12. package/dist/cjs/functions/getNames.js +6 -6
  13. package/dist/cjs/functions/getOwner.js +10 -9
  14. package/dist/cjs/functions/getPrice.js +4 -4
  15. package/dist/cjs/functions/getProfile.js +10 -10
  16. package/dist/cjs/functions/getResolver.js +2 -2
  17. package/dist/cjs/functions/getSpecificRecord.js +6 -6
  18. package/dist/cjs/functions/getSubnames.js +4 -4
  19. package/dist/cjs/functions/getWrapperData.js +2 -2
  20. package/dist/cjs/functions/importDNSSECName.js +5 -5
  21. package/dist/cjs/functions/initialGetters.js +3 -1
  22. package/dist/cjs/functions/setName.js +3 -2
  23. package/dist/cjs/functions/setRecord.js +2 -1
  24. package/dist/cjs/functions/setRecords.js +2 -1
  25. package/dist/cjs/functions/setResolver.js +2 -2
  26. package/dist/cjs/functions/supportsTLD.js +48 -0
  27. package/dist/cjs/functions/transferController.js +2 -2
  28. package/dist/cjs/functions/transferName.js +3 -3
  29. package/dist/cjs/functions/wrapName.js +3 -3
  30. package/dist/cjs/generated/factories/BaseRegistrarImplementation__factory.js +1 -1
  31. package/dist/cjs/generated/factories/BulkRenewal__factory.js +1 -1
  32. package/dist/cjs/generated/factories/DNSRegistrar__factory.js +1 -1
  33. package/dist/cjs/generated/factories/DNSSECImpl__factory.js +1 -1
  34. package/dist/cjs/generated/factories/DefaultReverseResolver__factory.js +1 -1
  35. package/dist/cjs/generated/factories/ENSRegistry__factory.js +1 -1
  36. package/dist/cjs/generated/factories/ETHRegistrarController__factory.js +1 -1
  37. package/dist/cjs/generated/factories/Multicall__factory.js +1 -1
  38. package/dist/cjs/generated/factories/NameWrapper__factory.js +1 -1
  39. package/dist/cjs/generated/factories/P256SHA256Algorithm__factory.js +1 -1
  40. package/dist/cjs/generated/factories/PublicResolver__factory.js +1 -1
  41. package/dist/cjs/generated/factories/RSASHA1Algorithm__factory.js +1 -1
  42. package/dist/cjs/generated/factories/RSASHA256Algorithm__factory.js +1 -1
  43. package/dist/cjs/generated/factories/ReverseRegistrar__factory.js +1 -1
  44. package/dist/cjs/generated/factories/Root__factory.js +1 -1
  45. package/dist/cjs/generated/factories/SHA1Digest__factory.js +1 -1
  46. package/dist/cjs/generated/factories/SHA1NSEC3Digest__factory.js +1 -1
  47. package/dist/cjs/generated/factories/SHA256Digest__factory.js +1 -1
  48. package/dist/cjs/generated/factories/StaticMetadataService__factory.js +1 -1
  49. package/dist/cjs/generated/factories/TLDPublicSuffixList__factory.js +1 -1
  50. package/dist/cjs/generated/factories/UniversalResolver__factory.js +1 -1
  51. package/dist/cjs/index.js +295 -291
  52. package/dist/cjs/utils/labels.js +1 -1
  53. package/dist/cjs/utils/recordHelpers.js +1 -1
  54. package/dist/cjs/utils/registerHelpers.js +2 -1
  55. package/dist/cjs/utils/wrapper.js +1 -1
  56. package/dist/esm/contracts/getContractAddress.mjs +1 -1
  57. package/dist/esm/functions/initialGetters.mjs +3 -1
  58. package/dist/esm/functions/supportsTLD.mjs +29 -0
  59. package/dist/esm/index.mjs +9 -1
  60. package/dist/types/functions/initialGetters.d.ts +1 -0
  61. package/dist/types/functions/supportsTLD.d.ts +2 -0
  62. package/dist/types/index.d.ts +6 -1
  63. package/package.json +1 -1
  64. package/src/contracts/getContractAddress.ts +1 -1
  65. package/src/functions/initialGetters.ts +1 -0
  66. package/src/functions/supportsTLD.test.ts +45 -0
  67. package/src/functions/supportsTLD.ts +38 -0
  68. package/src/index.ts +12 -1
@@ -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
+ };
@@ -38,10 +38,13 @@ var ENS = class {
38
38
  const thisRef = this;
39
39
  const mainFunc = async function(...args) {
40
40
  await thisRef.checkInitialProvider();
41
- const mod = await import(
41
+ let mod = await import(
42
42
  /* webpackMode: "lazy", webpackChunkName: "[request]", webpackPreload: true, webpackExclude: /.*\.ts$/ */
43
43
  `./functions/${path}`
44
44
  );
45
+ if (mod.default?.[exportName]) {
46
+ mod = mod.default;
47
+ }
45
48
  if (subFunc !== "combine") {
46
49
  const writeable = subFunc === "write" || subFunc === "populateTransaction";
47
50
  const func = subFunc && !writeable ? mod[exportName][subFunc] : mod[exportName];
@@ -233,6 +236,11 @@ var ENS = class {
233
236
  "getDNSOwner",
234
237
  []
235
238
  );
239
+ supportsTLD = this.generateFunction(
240
+ "initialGetters",
241
+ ["getOwner", "provider"],
242
+ "supportsTLD"
243
+ );
236
244
  getAvailable = this.generateRawFunction(
237
245
  "getAvailable",
238
246
  ["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.38",
4
4
  "description": "ENS javascript library for contract interaction",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "module": "./dist/esm/index.mjs",
@@ -46,7 +46,7 @@ const addresses: Record<
46
46
  '5': '0xD5610A08E370051a01fdfe4bB3ddf5270af1aA48',
47
47
  },
48
48
  UniversalResolver: {
49
- '1': '0x580AF46E06DaaD47eb5940526FD64d95b815Cb70',
49
+ '1': '0x74E20Bd2A1fE0cdbe45b9A1d89cb7e0a45b36376',
50
50
  '3': '0x74e20bd2a1fe0cdbe45b9a1d89cb7e0a45b36376',
51
51
  '4': '0x74e20bd2a1fe0cdbe45b9a1d89cb7e0a45b36376',
52
52
  '5': '0x687c30Cc44bFA39A1449e86E172BF002E7b3f0b0',
@@ -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
@@ -45,6 +45,7 @@ import type setName from './functions/setName'
45
45
  import type setRecord from './functions/setRecord'
46
46
  import type setRecords from './functions/setRecords'
47
47
  import type setResolver from './functions/setResolver'
48
+ import type supportsTLD from './functions/supportsTLD'
48
49
  import type transferController from './functions/transferController'
49
50
  import type transferName from './functions/transferName'
50
51
  import type transferSubname from './functions/transferSubname'
@@ -258,10 +259,14 @@ export class ENS {
258
259
  // check the initial provider and set if it exists
259
260
  await thisRef.checkInitialProvider()
260
261
  // import the module dynamically
261
- const mod = await import(
262
+ let mod = await import(
262
263
  /* webpackMode: "lazy", webpackChunkName: "[request]", webpackPreload: true, webpackExclude: /.*\.ts$/ */
263
264
  `./functions/${path}`
264
265
  )
266
+ // if export is nested in default, use default
267
+ if (mod.default?.[exportName]) {
268
+ mod = mod.default
269
+ }
265
270
 
266
271
  // if combine isn't specified, run normally
267
272
  // otherwise, create a function from the raw and decode functions
@@ -548,6 +553,12 @@ export class ENS {
548
553
  [],
549
554
  )
550
555
 
556
+ public supportsTLD = this.generateFunction<typeof supportsTLD>(
557
+ 'initialGetters',
558
+ ['getOwner', 'provider'],
559
+ 'supportsTLD',
560
+ )
561
+
551
562
  public getAvailable = this.generateRawFunction<typeof getAvailable>(
552
563
  'getAvailable',
553
564
  ['contracts'],