From 63144eb138beb0724e323514f36688e966c3416c Mon Sep 17 00:00:00 2001 From: Joseph Werle Date: Wed, 14 Apr 2021 12:34:50 -0400 Subject: [PATCH 1/2] Introduce support for Ara --- README.md | 1 + protocols.js | 11 ++++++++++ test/integration.test.js | 15 +++++++++++++- test/protocols.test.js | 45 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 71 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1dbd9c7..99244c2 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,7 @@ It implements various naming systems such as [dat][] or [cabal][] but is extensi [dat]: https://www.datprotocol.com/deps/0005-dns/ [cabal]: https://cabal.chat/ +[ara]: https://ara.one/ ## 🚀 Basic API diff --git a/protocols.js b/protocols.js index f467809..3c6a23e 100644 --- a/protocols.js +++ b/protocols.js @@ -20,5 +20,16 @@ module.exports = Object.freeze({ return record } return await context.fetchWellKnown(name, 'cabal', /^\s*(?:cabal:)?(?:\/\/)?(?[0-9a-f]{64})\s*$/i, 6) + }, + async ara (context, name) { + let record = context.matchRegex(name, /^(?[0-9a-f]{64})$/i) + if (record !== undefined) { + return record + } + record = await context.getDNSTxtRecord(name, /^\s*"?(?:did:ara:)(?[0-9a-f]{64})"?\s*$/i) + if (record !== undefined) { + return record + } + return await context.fetchWellKnown(name, 'ara', /^\s*(?:did:ara:)?(?:\/\/)?(?[0-9a-f]{64})\s*$/i, 6) } }) diff --git a/test/integration.test.js b/test/integration.test.js index 2465061..b745cc3 100644 --- a/test/integration.test.js +++ b/test/integration.test.js @@ -20,7 +20,20 @@ test(`Successful test against ${ecosystem}`, async t => { results, { dat: key, - cabal: null + cabal: null, + ara: null } ) }) + +test('Successful test against jwerle.pub', async t => { + t.equals( + await resolveProtocol('ara', 'jwerle.pub', { corsWarning: null, cache: null }), + '22dea0fbb722b20ab11469ed61b2409cb0ca774a285914f160071e4e9e3b8ca8' + ) + + t.equals( + await resolveProtocol('dat', 'jwerle.pub', { corsWarning: null, cache: null }), + '22dea0fbb722b20ab11469ed61b2409cb0ca774a285914f160071e4e9e3b8ca8' + ) +}) diff --git a/test/protocols.test.js b/test/protocols.test.js index bb94ec8..94209eb 100644 --- a/test/protocols.test.js +++ b/test/protocols.test.js @@ -93,3 +93,48 @@ const { matchRegex } = require('../resolve-context.js') ) }) })() + +;(() => { + const { ara } = protocols + const key = '22dea0fbb722b20ab11469ed61b2409cb0ca774a285914f160071e4e9e3b8ca8' + test('ara: local urls', async t => { + t.deepEquals( + await ara({ matchRegex }, key), + { key, ttl: null } + ) + }) + test('ara: looking for dns records', async t => { + const name = 'jwerle.pub' + t.deepEquals( + await ara({ + matchRegex, + async getDNSTxtRecord (domain, regex) { + t.equals(domain, name) + t.match(`did:ara:${key}`, regex) + return { key, ttl: 10 } + } + }, name), + { key, ttl: 10 } + ) + }) + test('ara: looking for well-known record', async t => { + const name = 'jwerle.pub' + t.deepEquals( + await ara({ + matchRegex, + async getDNSTxtRecord () { + return undefined + }, + async fetchWellKnown (domain, schema, regex, redirects) { + t.equals(redirects, 6) + t.equals(domain, name) + t.equals(schema, 'ara') + t.match(key, regex) + t.match(`did:ara:${key}`, regex) + return { key, ttl: 10 } + } + }, name), + { key, ttl: 10 } + ) + }) +})() From 2ab60f43eec35ad2f58f76b8b0ee94750bff5fd8 Mon Sep 17 00:00:00 2001 From: Martin Heidegger Date: Thu, 15 Apr 2021 03:27:11 +0900 Subject: [PATCH 2/2] v0.10.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 88e7b5d..2360d18 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hyper-dns", - "version": "0.9.0", + "version": "0.10.0", "description": "DNS lookup for dat/hyper archives", "main": "index.js", "browser": "browser.js",