@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.
- package/README.md +2 -0
- package/dist/cjs/functions/burnFuses.d.ts +1 -2
- package/dist/cjs/functions/burnFuses.js +3 -3
- package/dist/cjs/functions/createSubname.js +2 -1
- package/dist/cjs/functions/getDNSOwner.d.ts +7 -0
- package/dist/cjs/functions/getDNSOwner.js +81 -0
- package/dist/cjs/functions/getFuses.js +3 -2
- package/dist/cjs/functions/getOwner.js +7 -6
- package/dist/cjs/functions/getProfile.d.ts +1 -1
- package/dist/cjs/functions/getProfile.js +49 -15
- package/dist/cjs/functions/getSpecificRecord.js +22 -5
- package/dist/cjs/functions/getSubnames.js +6 -6
- package/dist/cjs/functions/setRecords.d.ts +1 -2
- package/dist/cjs/functions/setRecords.js +3 -3
- package/dist/cjs/functions/setResolver.d.ts +1 -2
- package/dist/cjs/functions/setResolver.js +3 -3
- package/dist/cjs/functions/transferName.js +3 -2
- package/dist/cjs/functions/transferSubname.js +2 -1
- package/dist/cjs/functions/unwrapName.js +2 -1
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.js +2 -0
- package/dist/cjs/utils/makeHashIndexes.js +2 -2
- package/dist/cjs/utils/normalise.d.ts +1 -0
- package/dist/cjs/utils/normalise.js +20 -1
- package/dist/cjs/utils/registerHelpers.js +3 -4
- package/dist/esm/functions/burnFuses.d.ts +1 -2
- package/dist/esm/functions/burnFuses.js +3 -3
- package/dist/esm/functions/createSubname.js +2 -1
- package/dist/esm/functions/getDNSOwner.d.ts +7 -0
- package/dist/esm/functions/getDNSOwner.js +51 -0
- package/dist/esm/functions/getFuses.js +4 -3
- package/dist/esm/functions/getOwner.js +7 -6
- package/dist/esm/functions/getProfile.d.ts +1 -1
- package/dist/esm/functions/getProfile.js +49 -15
- package/dist/esm/functions/getSpecificRecord.js +22 -5
- package/dist/esm/functions/getSubnames.js +3 -3
- package/dist/esm/functions/setRecords.d.ts +1 -2
- package/dist/esm/functions/setRecords.js +3 -3
- package/dist/esm/functions/setResolver.d.ts +1 -2
- package/dist/esm/functions/setResolver.js +3 -3
- package/dist/esm/functions/transferName.js +3 -2
- package/dist/esm/functions/transferSubname.js +2 -1
- package/dist/esm/functions/unwrapName.js +2 -1
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/utils/makeHashIndexes.js +2 -2
- package/dist/esm/utils/normalise.d.ts +1 -0
- package/dist/esm/utils/normalise.js +18 -0
- package/dist/esm/utils/registerHelpers.js +3 -4
- package/package.json +11 -5
- package/src/@types/dns-packet/index.d.ts +114 -0
- package/src/{tests → functions}/batch.test.ts +1 -1
- package/src/{tests → functions}/batchWrappers.test.ts +1 -1
- package/src/{tests → functions}/burnFuses.test.ts +4 -3
- package/src/functions/burnFuses.ts +3 -3
- package/src/{tests → functions}/createSubname.test.ts +5 -6
- package/src/functions/createSubname.ts +2 -1
- package/src/{tests → functions}/deleteSubname.test.ts +5 -6
- package/src/functions/getDNSOwner.test.ts +122 -0
- package/src/functions/getDNSOwner.ts +61 -0
- package/src/{tests → functions}/getExpiry.test.ts +1 -1
- package/src/{tests → functions}/getFuses.test.ts +1 -1
- package/src/functions/getFuses.ts +4 -3
- package/src/{tests → functions}/getHistory.test.ts +1 -1
- package/src/{tests → functions}/getName.test.ts +1 -1
- package/src/{tests → functions}/getNames.test.ts +1 -1
- package/src/{tests → functions}/getOwner.test.ts +11 -1
- package/src/functions/getOwner.ts +7 -7
- package/src/{tests → functions}/getProfile.test.ts +29 -11
- package/src/functions/getProfile.ts +77 -13
- package/src/{tests → functions}/getResolver.test.ts +1 -1
- package/src/{tests → functions}/getSpecificRecord.test.ts +1 -1
- package/src/functions/getSpecificRecord.ts +28 -8
- package/src/{tests → functions}/getSubnames.test.ts +1 -1
- package/src/functions/getSubnames.ts +68 -66
- package/src/{tests → functions}/makeCommitment.test.ts +1 -1
- package/src/functions/normalise.test.ts +22 -0
- package/src/{tests → functions}/setName.test.ts +1 -1
- package/src/{tests → functions}/setRecords.test.ts +4 -4
- package/src/functions/setRecords.ts +3 -3
- package/src/{tests → functions}/setResolver.test.ts +1 -1
- package/src/functions/setResolver.ts +3 -3
- package/src/{tests → functions}/transferName.test.ts +4 -3
- package/src/functions/transferName.ts +3 -2
- package/src/{tests → functions}/transferSubname.test.ts +5 -6
- package/src/functions/transferSubname.ts +2 -1
- package/src/{tests → functions}/unwrapName.test.ts +3 -2
- package/src/functions/unwrapName.ts +2 -1
- package/src/{tests → functions}/wrapName.test.ts +5 -8
- package/src/index.ts +7 -0
- package/src/tests/withProvider.test.ts +1 -1
- package/src/utils/makeHashIndexes.ts +4 -4
- package/src/utils/normalise.ts +23 -0
- 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
|
|
33
|
+
const hash = namehash(name)
|
|
34
34
|
|
|
35
|
-
const calls: string[] = generateRecordCallArray(
|
|
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 '
|
|
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(
|
|
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(
|
|
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
|
|
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(
|
|
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(
|
|
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(
|
|
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
|
-
|
|
48
|
+
namehash(name),
|
|
48
49
|
1,
|
|
49
50
|
'0x',
|
|
50
51
|
)
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { ethers
|
|
1
|
+
import { ethers } from 'ethers'
|
|
2
2
|
import { ENS } from '..'
|
|
3
|
-
import
|
|
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(
|
|
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 =
|
|
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
|
|
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(
|
|
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 =
|
|
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
|
|
1
|
+
import { BigNumber, ethers } from 'ethers'
|
|
2
2
|
import { ENS } from '..'
|
|
3
3
|
import { hexEncodeName } from '../utils/hexEncodedName'
|
|
4
|
-
import
|
|
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,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
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
|
-
|
|
9
|
-
)
|
|
7
|
+
Array.from(data.matchAll(namehash(name).substring(2) as any)).map(
|
|
8
|
+
(x: any) => x.index / 2 - 1,
|
|
9
|
+
)
|
package/src/utils/normalise.ts
CHANGED
|
@@ -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
|
|
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
|
|