Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Commit

Permalink
feat: resolution of .eth names via .eth.link
Browse files Browse the repository at this point in the history
.eth TLD is not recognised by mainstream DNS,
however ENS provides DNS compatibility service at .eth.link

This change enables resolution of ENS names ending with .eth
on systems that  have regular DNS set up

More context at the go-ipfs counterpart:
ipfs/kubo#6448

License: MIT
Signed-off-by: Marcin Rataj <[email protected]>
  • Loading branch information
lidel committed Aug 20, 2019
1 parent 3d29d60 commit 6f23a97
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/core/components/dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@
const dns = require('../runtime/dns-nodejs')
const promisify = require('promisify-es6')

function fqdnFixups (domain) {
// Allow resolution of .eth names via .eth.link
// More context at the go-ipfs counterpart: https://github.com/ipfs/go-ipfs/pull/6448
if (domain.endsWith('.eth')) {
domain = domain.replace(/.eth$/, '.eth.link')
}
return domain
}

module.exports = () => {
return promisify((domain, opts, callback) => {
if (typeof domain !== 'string') {
Expand All @@ -16,6 +25,7 @@ module.exports = () => {
}

opts = opts || {}
domain = fqdnFixups(domain)

dns(domain, opts, callback)
})
Expand Down
11 changes: 10 additions & 1 deletion test/http-api/inject/dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,22 @@ module.exports = (http) => {
api = http.api._httpApi._apiServers[0]
})

it('resolve ipfs.io dns', async () => {
it('resolve ipfs.io DNS', async () => {
const res = await api.inject({
method: 'GET',
url: '/api/v0/dns?arg=ipfs.io'
})

expect(res.result).to.have.property('Path')
})

it('resolve ipfs.enstest.eth ENS', async () => {
const res = await api.inject({
method: 'GET',
url: '/api/v0/dns?arg=ipfs.enstest.eth'
})

expect(res.result).to.have.property('Path')
})
})
}

0 comments on commit 6f23a97

Please sign in to comment.