@ensdomains/ensjs 3.0.0-alpha.1 → 3.0.0-alpha.4

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 (94) hide show
  1. package/README.md +2 -0
  2. package/dist/cjs/functions/burnFuses.d.ts +1 -2
  3. package/dist/cjs/functions/burnFuses.js +3 -3
  4. package/dist/cjs/functions/createSubname.js +2 -1
  5. package/dist/cjs/functions/getDNSOwner.d.ts +7 -0
  6. package/dist/cjs/functions/getDNSOwner.js +81 -0
  7. package/dist/cjs/functions/getFuses.js +3 -2
  8. package/dist/cjs/functions/getOwner.js +7 -6
  9. package/dist/cjs/functions/getProfile.d.ts +1 -1
  10. package/dist/cjs/functions/getProfile.js +49 -15
  11. package/dist/cjs/functions/getSpecificRecord.js +22 -5
  12. package/dist/cjs/functions/getSubnames.js +6 -6
  13. package/dist/cjs/functions/setRecords.d.ts +1 -2
  14. package/dist/cjs/functions/setRecords.js +3 -3
  15. package/dist/cjs/functions/setResolver.d.ts +1 -2
  16. package/dist/cjs/functions/setResolver.js +3 -3
  17. package/dist/cjs/functions/transferName.js +3 -2
  18. package/dist/cjs/functions/transferSubname.js +2 -1
  19. package/dist/cjs/functions/unwrapName.js +2 -1
  20. package/dist/cjs/index.d.ts +1 -0
  21. package/dist/cjs/index.js +2 -0
  22. package/dist/cjs/utils/makeHashIndexes.js +2 -2
  23. package/dist/cjs/utils/normalise.d.ts +1 -0
  24. package/dist/cjs/utils/normalise.js +20 -1
  25. package/dist/cjs/utils/registerHelpers.js +3 -4
  26. package/dist/esm/functions/burnFuses.d.ts +1 -2
  27. package/dist/esm/functions/burnFuses.js +3 -3
  28. package/dist/esm/functions/createSubname.js +2 -1
  29. package/dist/esm/functions/getDNSOwner.d.ts +7 -0
  30. package/dist/esm/functions/getDNSOwner.js +51 -0
  31. package/dist/esm/functions/getFuses.js +4 -3
  32. package/dist/esm/functions/getOwner.js +7 -6
  33. package/dist/esm/functions/getProfile.d.ts +1 -1
  34. package/dist/esm/functions/getProfile.js +49 -15
  35. package/dist/esm/functions/getSpecificRecord.js +22 -5
  36. package/dist/esm/functions/getSubnames.js +3 -3
  37. package/dist/esm/functions/setRecords.d.ts +1 -2
  38. package/dist/esm/functions/setRecords.js +3 -3
  39. package/dist/esm/functions/setResolver.d.ts +1 -2
  40. package/dist/esm/functions/setResolver.js +3 -3
  41. package/dist/esm/functions/transferName.js +3 -2
  42. package/dist/esm/functions/transferSubname.js +2 -1
  43. package/dist/esm/functions/unwrapName.js +2 -1
  44. package/dist/esm/index.d.ts +1 -0
  45. package/dist/esm/index.js +2 -0
  46. package/dist/esm/utils/makeHashIndexes.js +2 -2
  47. package/dist/esm/utils/normalise.d.ts +1 -0
  48. package/dist/esm/utils/normalise.js +18 -0
  49. package/dist/esm/utils/registerHelpers.js +3 -4
  50. package/package.json +11 -5
  51. package/src/@types/dns-packet/index.d.ts +114 -0
  52. package/src/{tests → functions}/batch.test.ts +1 -1
  53. package/src/{tests → functions}/batchWrappers.test.ts +1 -1
  54. package/src/{tests → functions}/burnFuses.test.ts +4 -3
  55. package/src/functions/burnFuses.ts +3 -3
  56. package/src/{tests → functions}/createSubname.test.ts +5 -6
  57. package/src/functions/createSubname.ts +2 -1
  58. package/src/{tests → functions}/deleteSubname.test.ts +5 -6
  59. package/src/functions/getDNSOwner.test.ts +122 -0
  60. package/src/functions/getDNSOwner.ts +61 -0
  61. package/src/{tests → functions}/getExpiry.test.ts +1 -1
  62. package/src/{tests → functions}/getFuses.test.ts +1 -1
  63. package/src/functions/getFuses.ts +4 -3
  64. package/src/{tests → functions}/getHistory.test.ts +1 -1
  65. package/src/{tests → functions}/getName.test.ts +1 -1
  66. package/src/{tests → functions}/getNames.test.ts +1 -1
  67. package/src/{tests → functions}/getOwner.test.ts +11 -1
  68. package/src/functions/getOwner.ts +7 -7
  69. package/src/{tests → functions}/getProfile.test.ts +29 -11
  70. package/src/functions/getProfile.ts +77 -13
  71. package/src/{tests → functions}/getResolver.test.ts +1 -1
  72. package/src/{tests → functions}/getSpecificRecord.test.ts +1 -1
  73. package/src/functions/getSpecificRecord.ts +28 -8
  74. package/src/{tests → functions}/getSubnames.test.ts +1 -1
  75. package/src/functions/getSubnames.ts +68 -66
  76. package/src/{tests → functions}/makeCommitment.test.ts +1 -1
  77. package/src/functions/normalise.test.ts +22 -0
  78. package/src/{tests → functions}/setName.test.ts +1 -1
  79. package/src/{tests → functions}/setRecords.test.ts +4 -4
  80. package/src/functions/setRecords.ts +3 -3
  81. package/src/{tests → functions}/setResolver.test.ts +1 -1
  82. package/src/functions/setResolver.ts +3 -3
  83. package/src/{tests → functions}/transferName.test.ts +4 -3
  84. package/src/functions/transferName.ts +3 -2
  85. package/src/{tests → functions}/transferSubname.test.ts +5 -6
  86. package/src/functions/transferSubname.ts +2 -1
  87. package/src/{tests → functions}/unwrapName.test.ts +3 -2
  88. package/src/functions/unwrapName.ts +2 -1
  89. package/src/{tests → functions}/wrapName.test.ts +5 -8
  90. package/src/index.ts +7 -0
  91. package/src/tests/withProvider.test.ts +1 -1
  92. package/src/utils/makeHashIndexes.ts +4 -4
  93. package/src/utils/normalise.ts +23 -0
  94. package/src/utils/registerHelpers.ts +3 -4
@@ -1,5 +1,5 @@
1
- import { ethers } from 'ethers'
2
1
  import { ENSArgs } from '..'
2
+ import { namehash } from '../utils/normalise'
3
3
  import { generateRecordCallArray, RecordOptions } from '../utils/recordHelpers'
4
4
 
5
5
  export default async function (
@@ -30,9 +30,9 @@ export default async function (
30
30
  const resolver = (
31
31
  await contracts?.getPublicResolver(provider, resolverAddress)
32
32
  )?.connect(provider?.getSigner()!)
33
- const namehash = ethers.utils.namehash(name)
33
+ const hash = namehash(name)
34
34
 
35
- const calls: string[] = generateRecordCallArray(namehash, records, resolver!)
35
+ const calls: string[] = generateRecordCallArray(hash, records, resolver!)
36
36
 
37
37
  return resolver?.multicall(calls)
38
38
  }
@@ -1,7 +1,7 @@
1
1
  import { ethers } from 'ethers'
2
2
  import { ENS } from '..'
3
3
  import { hexEncodeName } from '../utils/hexEncodedName'
4
- import setup from './setup'
4
+ import setup from '../tests/setup'
5
5
 
6
6
  let ENSInstance: ENS
7
7
  let revert: Awaited<ReturnType<typeof setup>>['revert']
@@ -1,5 +1,5 @@
1
- import { ethers } from 'ethers'
2
1
  import { ENSArgs } from '..'
2
+ import { namehash } from '../utils/normalise'
3
3
 
4
4
  export default async function (
5
5
  { contracts, provider }: ENSArgs<'contracts' | 'provider'>,
@@ -25,13 +25,13 @@ export default async function (
25
25
  const registry = (await contracts?.getRegistry())!.connect(
26
26
  provider?.getSigner(options?.addressOrIndex)!,
27
27
  )
28
- return registry.setResolver(ethers.utils.namehash(name), resolver)
28
+ return registry.setResolver(namehash(name), resolver)
29
29
  }
30
30
  case 'nameWrapper': {
31
31
  const nameWrapper = (await contracts?.getNameWrapper())!.connect(
32
32
  provider?.getSigner(options?.addressOrIndex)!,
33
33
  )
34
- return nameWrapper.setResolver(ethers.utils.namehash(name), resolver)
34
+ return nameWrapper.setResolver(namehash(name), resolver)
35
35
  }
36
36
  default: {
37
37
  throw new Error(`Unknown contract: ${contract}`)
@@ -1,6 +1,7 @@
1
1
  import { ethers, utils } from 'ethers'
2
2
  import { ENS } from '..'
3
- import setup from './setup'
3
+ import { namehash } from '../utils/normalise'
4
+ import setup from '../tests/setup'
4
5
 
5
6
  let ENSInstance: ENS
6
7
  let revert: Awaited<ReturnType<typeof setup>>['revert']
@@ -52,7 +53,7 @@ describe('transferName', () => {
52
53
  await tx.wait()
53
54
 
54
55
  const nameWrapper = await ENSInstance.contracts!.getNameWrapper()!
55
- const result = await nameWrapper.ownerOf(utils.namehash('parthtejpal.eth'))
56
+ const result = await nameWrapper.ownerOf(namehash('parthtejpal.eth'))
56
57
  expect(result).toBe(accounts[1])
57
58
  })
58
59
  it('should allow a transfer on the registry', async () => {
@@ -74,7 +75,7 @@ describe('transferName', () => {
74
75
  await tx.wait()
75
76
 
76
77
  const registry = await ENSInstance.contracts!.getRegistry()!
77
- const result = await registry.owner(utils.namehash('test.parthtejpal.eth'))
78
+ const result = await registry.owner(namehash('test.parthtejpal.eth'))
78
79
  expect(result).toBe(accounts[1])
79
80
  })
80
81
  })
@@ -1,5 +1,6 @@
1
1
  import { ethers } from 'ethers'
2
2
  import { ENSArgs } from '..'
3
+ import { namehash } from '../utils/normalise'
3
4
 
4
5
  export default async function (
5
6
  { contracts, provider }: ENSArgs<'contracts' | 'provider'>,
@@ -21,7 +22,7 @@ export default async function (
21
22
  const registry = (await contracts?.getRegistry())!.connect(
22
23
  provider?.getSigner(options?.addressOrIndex)!,
23
24
  )
24
- return registry.setOwner(ethers.utils.namehash(name), newOwner)
25
+ return registry.setOwner(namehash(name), newOwner)
25
26
  }
26
27
  case 'baseRegistrar': {
27
28
  const baseRegistrar = (await contracts?.getBaseRegistrar())!.connect(
@@ -44,7 +45,7 @@ export default async function (
44
45
  return nameWrapper.safeTransferFrom(
45
46
  address,
46
47
  newOwner,
47
- ethers.utils.namehash(name),
48
+ namehash(name),
48
49
  1,
49
50
  '0x',
50
51
  )
@@ -1,6 +1,7 @@
1
- import { ethers, utils } from 'ethers'
1
+ import { ethers } from 'ethers'
2
2
  import { ENS } from '..'
3
- import setup from './setup'
3
+ import { namehash } from '../utils/normalise'
4
+ import setup from '../tests/setup'
4
5
 
5
6
  let ENSInstance: ENS
6
7
  let revert: Awaited<ReturnType<typeof setup>>['revert']
@@ -39,7 +40,7 @@ describe('transferSubname', () => {
39
40
  await tx.wait()
40
41
 
41
42
  const registry = await ENSInstance.contracts!.getRegistry()!
42
- const result = await registry.owner(utils.namehash('test.parthtejpal.eth'))
43
+ const result = await registry.owner(namehash('test.parthtejpal.eth'))
43
44
  expect(result).toBe(accounts[1])
44
45
  })
45
46
  it('should allow transferring a subname on the nameWrapper', async () => {
@@ -66,9 +67,7 @@ describe('transferSubname', () => {
66
67
  await tx.wait()
67
68
 
68
69
  const nameWrapper = await ENSInstance.contracts!.getNameWrapper()!
69
- const result = await nameWrapper.ownerOf(
70
- utils.namehash('test.parthtejpal.eth'),
71
- )
70
+ const result = await nameWrapper.ownerOf(namehash('test.parthtejpal.eth'))
72
71
  expect(result).toBe(accounts[1])
73
72
  })
74
73
  })
@@ -1,5 +1,6 @@
1
1
  import { ethers } from 'ethers'
2
2
  import { ENSArgs } from '..'
3
+ import { namehash } from '../utils/normalise'
3
4
 
4
5
  export default async function (
5
6
  { contracts, provider }: ENSArgs<'contracts' | 'provider'>,
@@ -17,7 +18,7 @@ export default async function (
17
18
  const labels = name.split('.')
18
19
  const label = labels.shift() as string
19
20
  const labelhash = ethers.utils.solidityKeccak256(['string'], [label])
20
- const parentNodehash = ethers.utils.namehash(labels.join('.'))
21
+ const parentNodehash = namehash(labels.join('.'))
21
22
 
22
23
  switch (contract) {
23
24
  case 'registry': {
@@ -1,6 +1,7 @@
1
1
  import { ethers, utils } from 'ethers'
2
2
  import { ENS } from '..'
3
- import setup from './setup'
3
+ import { namehash } from '../utils/normalise'
4
+ import setup from '../tests/setup'
4
5
 
5
6
  let ENSInstance: ENS
6
7
  let revert: Awaited<ReturnType<typeof setup>>['revert']
@@ -61,7 +62,7 @@ describe('unwrapName', () => {
61
62
  await tx.wait()
62
63
 
63
64
  const registry = await ENSInstance.contracts!.getRegistry()!
64
- const result = await registry.owner(utils.namehash('test.parthtejpal.eth'))
65
+ const result = await registry.owner(namehash('test.parthtejpal.eth'))
65
66
  expect(result).toBe(accounts[0])
66
67
  })
67
68
  })
@@ -1,5 +1,6 @@
1
1
  import { utils } from 'ethers'
2
2
  import { ENSArgs } from '..'
3
+ import { namehash } from '../utils/normalise'
3
4
 
4
5
  export default async function (
5
6
  { contracts, provider }: ENSArgs<'contracts' | 'provider'>,
@@ -18,7 +19,7 @@ export default async function (
18
19
 
19
20
  const labels = name.split('.')
20
21
  const labelhash = utils.solidityKeccak256(['string'], [labels[0]])
21
- const parentNodehash = utils.namehash(labels.slice(1).join('.'))
22
+ const parentNodehash = namehash(labels.slice(1).join('.'))
22
23
 
23
24
  const nameWrapper = (await contracts?.getNameWrapper()!).connect(signer)
24
25
 
@@ -1,7 +1,8 @@
1
- import { BigNumber, ethers, utils } from 'ethers'
1
+ import { BigNumber, ethers } from 'ethers'
2
2
  import { ENS } from '..'
3
3
  import { hexEncodeName } from '../utils/hexEncodedName'
4
- import setup from './setup'
4
+ import { namehash } from '../utils/normalise'
5
+ import setup from '../tests/setup'
5
6
 
6
7
  let ENSInstance: ENS
7
8
  let revert: Awaited<ReturnType<typeof setup>>['revert']
@@ -28,9 +29,7 @@ describe('wrapName', () => {
28
29
  await tx.wait()
29
30
 
30
31
  const nameWrapper = await ENSInstance.contracts!.getNameWrapper()!
31
- const [result] = await nameWrapper.getFuses(
32
- utils.namehash('parthtejpal.eth'),
33
- )
32
+ const [result] = await nameWrapper.getFuses(namehash('parthtejpal.eth'))
34
33
  expect((result as BigNumber).toHexString()).toBe('0x40')
35
34
  })
36
35
  it('should allow initial fuses', async () => {
@@ -42,9 +41,7 @@ describe('wrapName', () => {
42
41
  await tx.wait()
43
42
 
44
43
  const nameWrapper = await ENSInstance.contracts!.getNameWrapper()!
45
- const [result] = await nameWrapper.getFuses(
46
- utils.namehash('parthtejpal.eth'),
47
- )
44
+ const [result] = await nameWrapper.getFuses(namehash('parthtejpal.eth'))
48
45
  expect((result as BigNumber).toHexString()).toBe('0x51')
49
46
  })
50
47
  it('should allow an initial resolver address', async () => {
package/src/index.ts CHANGED
@@ -41,6 +41,7 @@ import type transferName from './functions/transferName'
41
41
  import type transferSubname from './functions/transferSubname'
42
42
  import type unwrapName from './functions/unwrapName'
43
43
  import type wrapName from './functions/wrapName'
44
+ import type getDNSOwner from './functions/getDNSOwner'
44
45
  import GqlManager from './GqlManager'
45
46
  import singleCall from './utils/singleCall'
46
47
 
@@ -321,6 +322,7 @@ export class ENS {
321
322
  'gqlInstance',
322
323
  'getName',
323
324
  'resolverMulticallWrapper',
325
+ 'multicallWrapper',
324
326
  '_getAddr',
325
327
  '_getContentHash',
326
328
  '_getText',
@@ -503,4 +505,9 @@ export class ENS {
503
505
  'transferSubname',
504
506
  ['contracts', 'provider'],
505
507
  )
508
+
509
+ public getDNSOwner = this.generateFunction<typeof getDNSOwner>(
510
+ 'getDNSOwner',
511
+ [],
512
+ )
506
513
  }
@@ -1,6 +1,6 @@
1
1
  import { ethers } from 'ethers'
2
2
  import { ENS } from '..'
3
- import setup from './setup'
3
+ import setup from '../tests/setup'
4
4
 
5
5
  let ENSInstance: ENS
6
6
  let providerFake: ethers.providers.JsonRpcProvider
@@ -1,9 +1,9 @@
1
- import { ethers } from 'ethers'
1
+ import { namehash } from './normalise'
2
2
 
3
3
  export const makeOtherIndexes = (data: string, findStr: string) =>
4
4
  Array.from(data.matchAll(findStr as any)).map((x: any) => x.index / 2 - 1)
5
5
 
6
6
  export const makeNamehashIndexes = (data: string, name: string) =>
7
- Array.from(
8
- data.matchAll(ethers.utils.namehash(name).substring(2) as any),
9
- ).map((x: any) => x.index / 2 - 1)
7
+ Array.from(data.matchAll(namehash(name).substring(2) as any)).map(
8
+ (x: any) => x.index / 2 - 1,
9
+ )
@@ -1,4 +1,27 @@
1
+ import { concat, hexlify, keccak256, toUtf8Bytes } from 'ethers/lib/utils'
1
2
  import uts46 from 'idna-uts46-hx/uts46bundle.js'
2
3
 
4
+ const zeros = new Uint8Array(32)
5
+ zeros.fill(0)
6
+
3
7
  export const normalise = (name: string) =>
4
8
  name ? uts46.toUnicode(name, { useStd3ASCII: true }) : name
9
+
10
+ export const namehash = (inputName: string): string => {
11
+ let result: string | Uint8Array = zeros
12
+
13
+ const name = normalise(inputName)
14
+
15
+ if (name) {
16
+ const labels = name.split('.')
17
+
18
+ for (var i = labels.length - 1; i >= 0; i--) {
19
+ const labelSha = keccak256(toUtf8Bytes(labels[i]))
20
+ result = keccak256(concat([result, labelSha]))
21
+ }
22
+ } else {
23
+ result = hexlify(zeros)
24
+ }
25
+
26
+ return result as string
27
+ }
@@ -3,6 +3,7 @@ import type { FuseOptions } from '../@types/FuseOptions'
3
3
  import type { PublicResolver } from '../generated'
4
4
  import generateFuseInput from './generateFuseInput'
5
5
  import { labelhash } from './labels'
6
+ import { namehash } from './normalise'
6
7
  import { generateRecordCallArray, RecordOptions } from './recordHelpers'
7
8
 
8
9
  export const randomSecret = () => {
@@ -28,11 +29,9 @@ export const makeCommitment = ({
28
29
  fuses?: FuseOptions
29
30
  }) => {
30
31
  const label = labelhash(name.split('.')[0])
31
- const namehash = utils.namehash(name)
32
+ const hash = namehash(name)
32
33
  const resolverAddress = resolver.address
33
- const data = records
34
- ? generateRecordCallArray(namehash, records, resolver)
35
- : []
34
+ const data = records ? generateRecordCallArray(hash, records, resolver) : []
36
35
  const secret = randomSecret()
37
36
  const fuseData = fuses ? generateFuseInput(fuses) : '0'
38
37