Skip to content

Commit 7b489ba

Browse files
Merge branch 'main' into hyper-protocol
2 parents fb785cd + 2ab60f4 commit 7b489ba

File tree

5 files changed

+73
-2
lines changed

5 files changed

+73
-2
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ It implements various naming systems such as [dat][], [hyper][] and [cabal][] bu
66
[hyper]: https://hypercore-protocol.org/
77
[dat]: https://www.datprotocol.com/deps/0005-dns/
88
[cabal]: https://cabal.chat/
9+
[ara]: https://ara.one/
910

1011
## 🚀 Basic API
1112

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "hyper-dns",
3-
"version": "0.9.0",
3+
"version": "0.10.0",
44
"description": "DNS lookup for dat/hyper archives",
55
"main": "index.js",
66
"browser": "browser.js",

protocols.js

+11
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,16 @@ module.exports = Object.freeze({
4646
return record
4747
}
4848
return await context.fetchWellKnown(name, 'cabal', /^\s*(?:cabal:)?(?:\/\/)?(?<key>[0-9a-f]{64})\s*$/i, 6)
49+
},
50+
async ara (context, name) {
51+
let record = context.matchRegex(name, /^(?<key>[0-9a-f]{64})$/i)
52+
if (record !== undefined) {
53+
return record
54+
}
55+
record = await context.getDNSTxtRecord(name, /^\s*"?(?:did:ara:)(?<key>[0-9a-f]{64})"?\s*$/i)
56+
if (record !== undefined) {
57+
return record
58+
}
59+
return await context.fetchWellKnown(name, 'ara', /^\s*(?:did:ara:)?(?:\/\/)?(?<key>[0-9a-f]{64})\s*$/i, 6)
4960
}
5061
})

test/integration.test.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,21 @@ test(`Successful test against ${ecosystem}`, async t => {
2121
{
2222
dat: key,
2323
hyper: null,
24-
cabal: null
24+
cabal: null,
25+
cabal: null,
26+
ara: null
2527
}
2628
)
2729
})
30+
31+
test('Successful test against jwerle.pub', async t => {
32+
t.equals(
33+
await resolveProtocol('ara', 'jwerle.pub', { corsWarning: null, cache: null }),
34+
'22dea0fbb722b20ab11469ed61b2409cb0ca774a285914f160071e4e9e3b8ca8'
35+
)
36+
37+
t.equals(
38+
await resolveProtocol('dat', 'jwerle.pub', { corsWarning: null, cache: null }),
39+
'22dea0fbb722b20ab11469ed61b2409cb0ca774a285914f160071e4e9e3b8ca8'
40+
)
41+
})

test/protocols.test.js

+45
Original file line numberDiff line numberDiff line change
@@ -187,3 +187,48 @@ const { matchRegex } = require('../resolve-context.js')
187187
)
188188
})
189189
})()
190+
191+
;(() => {
192+
const { ara } = protocols
193+
const key = '22dea0fbb722b20ab11469ed61b2409cb0ca774a285914f160071e4e9e3b8ca8'
194+
test('ara: local urls', async t => {
195+
t.deepEquals(
196+
await ara({ matchRegex }, key),
197+
{ key, ttl: null }
198+
)
199+
})
200+
test('ara: looking for dns records', async t => {
201+
const name = 'jwerle.pub'
202+
t.deepEquals(
203+
await ara({
204+
matchRegex,
205+
async getDNSTxtRecord (domain, regex) {
206+
t.equals(domain, name)
207+
t.match(`did:ara:${key}`, regex)
208+
return { key, ttl: 10 }
209+
}
210+
}, name),
211+
{ key, ttl: 10 }
212+
)
213+
})
214+
test('ara: looking for well-known record', async t => {
215+
const name = 'jwerle.pub'
216+
t.deepEquals(
217+
await ara({
218+
matchRegex,
219+
async getDNSTxtRecord () {
220+
return undefined
221+
},
222+
async fetchWellKnown (domain, schema, regex, redirects) {
223+
t.equals(redirects, 6)
224+
t.equals(domain, name)
225+
t.equals(schema, 'ara')
226+
t.match(key, regex)
227+
t.match(`did:ara:${key}`, regex)
228+
return { key, ttl: 10 }
229+
}
230+
}, name),
231+
{ key, ttl: 10 }
232+
)
233+
})
234+
})()

0 commit comments

Comments
 (0)