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

feat: resolution of .eth names via .eth.link #2373

Merged
merged 1 commit into from
Aug 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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')
})
})
}