From 6f23a97d986f0d209a87d2d9fdbad8624697a1d1 Mon Sep 17 00:00:00 2001 From: Marcin Rataj Date: Tue, 20 Aug 2019 18:58:56 +0200 Subject: [PATCH] feat: resolution of .eth names via .eth.link .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: https://github.com/ipfs/go-ipfs/pull/6448 License: MIT Signed-off-by: Marcin Rataj --- src/core/components/dns.js | 10 ++++++++++ test/http-api/inject/dns.js | 11 ++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/core/components/dns.js b/src/core/components/dns.js index 55d81f1c04..7a083fdd6c 100644 --- a/src/core/components/dns.js +++ b/src/core/components/dns.js @@ -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') { @@ -16,6 +25,7 @@ module.exports = () => { } opts = opts || {} + domain = fqdnFixups(domain) dns(domain, opts, callback) }) diff --git a/test/http-api/inject/dns.js b/test/http-api/inject/dns.js index 18f0ec5925..ee2a4e88ca 100644 --- a/test/http-api/inject/dns.js +++ b/test/http-api/inject/dns.js @@ -11,7 +11,7 @@ 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' @@ -19,5 +19,14 @@ module.exports = (http) => { 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') + }) }) }