Skip to content

Commit

Permalink
Merge pull request #17 from ensdomains/dns-owner
Browse files Browse the repository at this point in the history
Dns owner
  • Loading branch information
LeonmanRolls authored Jul 7, 2022
2 parents 51a411d + e8dd990 commit bea0d2f
Show file tree
Hide file tree
Showing 41 changed files with 323 additions and 53 deletions.
Binary file added .DS_Store
Binary file not shown.
75 changes: 57 additions & 18 deletions .pnp.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions packages/ensjs/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const config = {
'^.+\\.(t|j)sx?$': ['@swc/jest'],
},
setupFilesAfterEnv: ['<rootDir>/jest.setup.ts'],
transformIgnorePatterns: []
}

export default config
4 changes: 4 additions & 0 deletions packages/ensjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"generate-abis": "hardhat export-abi",
"start": "ts-node --files src/index.test.ts",
"test": "jest --run-in-band src/tests",
"test:watch": "jest --watch --run-in-band src/tests",
"test:specific": "ts-node --files ",
"clean": "rm -rf ./dist ./README.md ./LICENSE",
"build:esm": "tsc --project tsconfig.esm.json",
Expand Down Expand Up @@ -57,6 +58,7 @@
"@swc/jest": "^0.2.20",
"@typechain/ethers-v5": "^10.0.0",
"@types/bn.js": "^5.1.0",
"@types/dns-packet": "^5.2.4",
"@types/jest": "^27.4.1",
"dotenv": "^16.0.0",
"ens-contracts": "github:ensdomains/ens-contracts#head=master&commit=3ecc56b14beb4aae8296f8a94f7c0d095e62fd93",
Expand All @@ -66,6 +68,8 @@
"jest": "^27.5.1",
"jest-environment-node": "^27.5.1",
"jest-localstorage-mock": "^2.4.21",
"nock": "^13.2.8",
"node-fetch": "^3.2.6",
"solc": "^0.8.13",
"ts-jest": "^27.1.4",
"ts-node": "^10.7.0",
Expand Down
1 change: 0 additions & 1 deletion packages/ensjs/src/@types/dns-packet.d.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ENS } from '..'
import setup from './setup'
import setup from '../tests/setup'

let ENSInstance: ENS

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ENS } from '..'
import setup from './setup'
import setup from '../tests/setup'

let ENSInstance: ENS

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { BigNumber, ethers } from 'ethers'
import { ENS } from '..'
import { namehash } from '../utils/normalise'
import setup from './setup'
import setup from '../tests/setup'

let ENSInstance: ENS
let revert: Awaited<ReturnType<typeof setup>>['revert']
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ethers } from 'ethers'
import { ENS } from '..'
import { namehash } from '../utils/normalise'
import setup from './setup'
import setup from '../tests/setup'

let ENSInstance: ENS
let revert: Awaited<ReturnType<typeof setup>>['revert']
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ethers } from 'ethers'
import { ENS } from '..'
import { namehash } from '../utils/normalise'
import setup from './setup'
import setup from '../tests/setup'

let ENSInstance: ENS
let revert: Awaited<ReturnType<typeof setup>>['revert']
Expand Down
122 changes: 122 additions & 0 deletions packages/ensjs/src/functions/getDNSOwner.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
import * as packet from 'dns-packet'
import fetch from 'node-fetch'
import nock from 'nock'

import getDNSOwner, { encodeURLParams } from './getDNSOwner'

function hex_decode(string: string) {
let bytes: any[] = []
string.replace(/../g, function (pair) {
bytes.push(parseInt(pair, 16))
})
return new Uint8Array(bytes).buffer
}

describe('encodeURLParams', () => {
it('should encodeURLParams', () => {
const p: { [key: string]: string } = {
a: 'b',
c: 'd',
}
const expected = 'a=b&c=d'
const actual = encodeURLParams(p)
expect(actual).toEqual(expected)
})
})

describe('getDNSOwner', () => {
beforeAll(() => {
global.fetch = fetch
})
afterAll(() => {
global.fetch = undefined
})
it('should return the address from the result of a dnsQuery', async () => {
const dnsName = 'brantly.xyz'

const scope = nock('https://cloudflare-dns.com:443', {
encodedQueryParams: true,
})
.get('/dns-query')
.query((queryObject) => {
console.log('queryObject: ', queryObject)
return (
queryObject.ct === 'application/dns-udpwireformat' &&
queryObject.dns ===
'AAEBAAABAAAAAAABBF9lbnMHYnJhbnRseQN4eXoAABAAAQAAKRAAAACAAAAA'
)
})
.reply(
200,
Buffer.from(
hex_decode(
'000181a00001000200000001045f656e73076272616e746c790378797a0000100001c00c0010000100000e10002d2c613d307839383331313033303936323044393131373331416330393332323139616630363039316236373434c00c002e000100000e10009f0010080300000e1062df366962c23569d89d076272616e746c790378797a0039c894ca1d7a60c1356e478066d39961a78ec1edbe62e1eb0f13d7947bb72097654648dc79be075ca32625f02e60267f45e88d7c05e9c3ec0cf21ab2dca67a8fbeb8e995644726357628446b888a144cafef5cbfca120c6511fe36de9d3c62dee27680825190c5404ca503904b98dbf62d9122f6fda393dc04b14a89ceb68c7a00002904d0000080000000',
),
),
[
'Server',
'cloudflare',
'Date',
'Wed, 06 Jul 2022 23:37:28 GMT',
'Content-Type',
'application/dns-message',
'Connection',
'close',
'Access-Control-Allow-Origin',
'*',
'Content-Length',
'273',
'CF-RAY',
'726c2b1d3bab6b74-TPE',
],
)
expect(await getDNSOwner(dnsName)).toEqual(
'0x983110309620D911731Ac0932219af06091b6744',
)
})
it('should throw if there is an error in the DNS query', async () => {
const dnsName = 'nick.xyz'

const scope = nock('https://cloudflare-dns.com:443', {
encodedQueryParams: true,
})
.get('/dns-query')
.query((queryObject) => {
console.log('queryObject: ', queryObject)
return (
queryObject.ct === 'application/dns-udpwireformat' &&
queryObject.dns ===
'AAEBAAABAAAAAAABBF9lbnMEbmljawN4eXoAABAAAQAAKRAAAACAAAAA'
)
})
.reply(
200,
Buffer.from(
hex_decode(
'000181830001000000010001045f656e73046e69636b0378797a0000100001c0110006000100000258003b046e7337310d646f6d61696e636f6e74726f6c03636f6d0003646e73056a6f6d6178036e6574007876d1800000708000001c2000093a800000025800002904d0000080000000',
),
),
[
'Server',
'cloudflare',
'Date',
'Wed, 06 Jul 2022 23:37:28 GMT',
'Content-Type',
'application/dns-message',
'Connection',
'close',
'Access-Control-Allow-Origin',
'*',
'Content-Length',
'273',
'CF-RAY',
'726c2b1d3bab6b74-TPE',
],
)
try {
await getDNSOwner(dnsName)
} catch (error) {
expect(error.message).toEqual('DNS query failed: NXDOMAIN')
}
})
})
Loading

0 comments on commit bea0d2f

Please sign in to comment.