Skip to content

Commit

Permalink
Merge branch 'main' into hyper-protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
martinheidegger authored Apr 15, 2021
2 parents fb785cd + 2ab60f4 commit 7b489ba
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ It implements various naming systems such as [dat][], [hyper][] and [cabal][] bu
[hyper]: https://hypercore-protocol.org/
[dat]: https://www.datprotocol.com/deps/0005-dns/
[cabal]: https://cabal.chat/
[ara]: https://ara.one/

## 🚀 Basic API

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
11 changes: 11 additions & 0 deletions protocols.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,16 @@ module.exports = Object.freeze({
return record
}
return await context.fetchWellKnown(name, 'cabal', /^\s*(?:cabal:)?(?:\/\/)?(?<key>[0-9a-f]{64})\s*$/i, 6)
},
async ara (context, name) {
let record = context.matchRegex(name, /^(?<key>[0-9a-f]{64})$/i)
if (record !== undefined) {
return record
}
record = await context.getDNSTxtRecord(name, /^\s*"?(?:did:ara:)(?<key>[0-9a-f]{64})"?\s*$/i)
if (record !== undefined) {
return record
}
return await context.fetchWellKnown(name, 'ara', /^\s*(?:did:ara:)?(?:\/\/)?(?<key>[0-9a-f]{64})\s*$/i, 6)
}
})
16 changes: 15 additions & 1 deletion test/integration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,21 @@ test(`Successful test against ${ecosystem}`, async t => {
{
dat: key,
hyper: null,
cabal: null
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'
)
})
45 changes: 45 additions & 0 deletions test/protocols.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,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 }
)
})
})()

0 comments on commit 7b489ba

Please sign in to comment.