nostr-tools 0.19.0 → 0.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/nip05.js +19 -45
- package/package.json +2 -2
package/nip05.js
CHANGED
|
@@ -1,52 +1,26 @@
|
|
|
1
|
-
import
|
|
2
|
-
import dnsPacket from 'dns-packet'
|
|
1
|
+
import fetch from 'cross-fetch'
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
'doh.pl.ahadns.net',
|
|
10
|
-
'dns.flatuslifir.is',
|
|
11
|
-
'doh.dns.sb',
|
|
12
|
-
'doh.li'
|
|
13
|
-
]
|
|
14
|
-
|
|
15
|
-
let counter = 0
|
|
16
|
-
|
|
17
|
-
export async function keyFromDomain(domain) {
|
|
18
|
-
let host = dohProviders[counter % dohProviders.length]
|
|
19
|
-
|
|
20
|
-
let buf = dnsPacket.encode({
|
|
21
|
-
type: 'query',
|
|
22
|
-
id: Math.floor(Math.random() * 65534),
|
|
23
|
-
flags: dnsPacket.RECURSION_DESIRED,
|
|
24
|
-
questions: [
|
|
25
|
-
{
|
|
26
|
-
type: 'TXT',
|
|
27
|
-
name: `_nostrkey.${domain}`
|
|
28
|
-
}
|
|
29
|
-
]
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
let fetching = fetch(`https://${host}/dns-query`, {
|
|
33
|
-
method: 'POST',
|
|
34
|
-
headers: {
|
|
35
|
-
'Content-Type': 'application/dns-message',
|
|
36
|
-
'Content-Length': Buffer.byteLength(buf)
|
|
37
|
-
},
|
|
38
|
-
body: buf
|
|
39
|
-
})
|
|
3
|
+
export async function searchDomain(domain, query = '') {
|
|
4
|
+
try {
|
|
5
|
+
let res = await (
|
|
6
|
+
await fetch(`https://${domain}/.well-known/nostr.json?name=${query}`)
|
|
7
|
+
).json()
|
|
40
8
|
|
|
41
|
-
|
|
9
|
+
return res.names
|
|
10
|
+
} catch (_) {
|
|
11
|
+
return []
|
|
12
|
+
}
|
|
13
|
+
}
|
|
42
14
|
|
|
15
|
+
export async function queryName(fullname) {
|
|
43
16
|
try {
|
|
44
|
-
let
|
|
45
|
-
let
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
17
|
+
let [name, domain] = fullname.split('@')
|
|
18
|
+
let res = await (
|
|
19
|
+
await fetch(`https://${domain}/.well-known/nostr.json?name=${name}`)
|
|
20
|
+
).json()
|
|
21
|
+
|
|
22
|
+
return res.names && res.names[name]
|
|
23
|
+
} catch (_) {
|
|
50
24
|
return null
|
|
51
25
|
}
|
|
52
26
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nostr-tools",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.20.0",
|
|
4
4
|
"description": "Tools for making a Nostr client.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"browserify-cipher": ">=1",
|
|
13
13
|
"buffer": ">=5",
|
|
14
14
|
"create-hash": "^1.2.0",
|
|
15
|
-
"
|
|
15
|
+
"cross-fetch": "^3.1.4",
|
|
16
16
|
"micro-bip32": "^0.1.0",
|
|
17
17
|
"micro-bip39": "^0.1.3",
|
|
18
18
|
"websocket-polyfill": "^0.0.3"
|