forked from handshake-org/hs-names
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.js
executable file
·273 lines (218 loc) · 7.15 KB
/
update.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
#!/usr/bin/env node
'use strict';
// TLD Resources:
// https://www.icann.org/resources/pages/tlds-2012-02-25-en
// https://data.iana.org/TLD/tlds-alpha-by-domain.txt
// https://www.internic.net/domain/root.zone
// SLD Resources:
// https://www.google.com/search?q=alexa+top+100000
// https://www.quora.com/What-are-the-top-100-000-most-visited-websites
// https://s3.amazonaws.com/alexa-static/top-1m.csv.zip
const assert = require('assert');
const fs = require('bfile');
const Path = require('path');
const {fromZone} = require('bns/lib/wire');
const {countLabels, trimFQDN} = require('bns/lib/util');
const util = require('./util');
const TLD_PATH = Path.resolve(__dirname, 'data', 'tlds-alpha-by-domain.txt');
const ALEXA_PATH = Path.resolve(__dirname, 'data', 'top-1m.csv');
const ROOT_PATH = Path.resolve(__dirname, 'data', 'root.zone');
const WORDS_PATH = '/usr/share/dict/words';
// These names are blacklisted entirely.
const BLACKLIST = [
'example', // ICANN reserved
'invalid', // ICANN reserved
'local', // mDNS
'localhost', // ICANN reserved
'test' // ICANN reserved
];
// These names are also blacklisted
// by policy rules, but are given to
// other naming projects in case they
// want to create some kind of
// compatibility bridge. Their name
// can be removed from policy rules
// later.
const CUSTOM = [
['bit', 'bit.namecoin.org'], // Namecoin
['eth', 'eth.ens.domains'], // ENS
['exit', 'exit.torproject.com'], // Tor
['gnu', 'gnu.gplv3.com'], // GNUnet (GNS)
['i2p', 'i2p.geti2p.net'], // Invisible Internet Project
['onion', 'onion.torproject.com'], // Tor
['tor', 'tor.torproject.com'], // Tor (OnioNS)
['zkey', 'zkey.gplv3.com'], // GNS
// Required to make the custom values work:
['afilias', 'afilias.info'], // Afilias plc (does not rank)
['blockstack', 'blockstack.com'], // Blockstack (does not rank)
['brave', 'brave.com'], // Brave (english word)
['darksi', 'darksi.de'], // Individual (does not rank)
['datprotocol', 'datprotocol.com'], // Dat Project (does not rank)
['debian', 'debian.net'], // Debian (prefer over .org)
['dnscrypt', 'dnscrypt.info'], // DNScrypt (does not rank)
['eff', 'eff.com'], // Electronic Frontier Foundation (prefer over .org)
['gnunet', 'gnunet.org'], // GNUnet (does not rank)
['keybase', 'keybase.io'], // Keybase (prefer over keybase.pub)
['m-d', 'm-d.net'], // Individual (does not rank)
['marples', 'marples.name'], // Individual (does not rank)
['mozilla', 'mozilla.com'], // Mozilla Foundation (prefer over .org)
['nlnetlabs', 'nlnetlabs.nl'], // Unbound (does not rank)
['numcalc', 'numcalc.com'], // Individual (does not rank)
['pir', 'pir.org'] // Public Internet Registry (does not rank)
].sort(([a], [b]) => {
return a.localeCompare(b);
});
const VALUES = [
['afilias.info', 3400000], // Afilias plc
['blockstack.com', 408000], // Blockstack
['brave.com', 3400000], // Brave
['cloudflare.com', 6800000], // Cloudflare
['darksi.de', 608957], // Individual
['datprotocol.com', 405970], // Dat Project
['debian.net', 1194838], // Reproducible Builds Debian
['dnscrypt.info', 202985], // DNScrypt
['eff.com', 710448], // Electronic Frontier Foundation
['eth.ens.domains', 136000], // ENS
['gnu.gplv3.com', 1194838], // GNU
['gnunet.org', 136000], // GNUnet
['godaddy', 2720000], // Godaddy
['icann.org', 24480000], // ICANN
['keybase.io', 3400000], // Keybase
['m-d.net', 1041987], // Individual
['marples.name', 202985], // openresolv
['mozilla.com', 608955], // Mozilla Foundation
['namecheap.com', 2720000], // Namecheap
['nlnetlabs.nl', 1194838], // Unbound
['numcalc.com', 710448], // Individual
['pir.org', 3400000], // Public Internet Registry
['riseup.net', 202985], // Riseup Labs
['tor.torproject.com', 1194838], // Tor Project
['ubuntu.com', 710448], // Ubuntu
['verisign', 6800000], // Verisign
['webtorrent.io', 405970], // WebTorrent LLC
];
const TLD = [
'arpa',
'com',
'edu',
'gov',
'int',
'mil',
'net',
'org'
];
const CCTLD = (() => {
const data = fs.readFileSync(TLD_PATH, 'utf8');
const lines = data.split('\n');
const result = [];
for (const line of lines) {
const name = line.trim().toLowerCase();
if (name.length === 0)
continue;
if (name[0] === '#')
continue;
assert(name.length <= 63);
// ccTLDs only!
if (util.isCCTLD(name))
result.push(name);
}
return result;
})();
const GTLD = (() => {
const data = fs.readFileSync(TLD_PATH, 'utf8');
const lines = data.split('\n');
const result = [];
for (const line of lines) {
const name = line.trim().toLowerCase();
if (name.length === 0)
continue;
if (name[0] === '#')
continue;
assert(name.length <= 63);
// gTLDs only!
if (util.isGTLD(name))
result.push(name);
}
return result;
})();
const RTLD = (() => {
const text = fs.readFileSync(ROOT_PATH, 'utf8');
const records = fromZone(text);
const set = new Set();
const result = [];
for (const rr of records) {
if (countLabels(rr.name) !== 1)
continue;
const name = rr.name.toLowerCase();
if (set.has(name))
continue;
set.add(name);
result.push(trimFQDN(name));
}
return result;
})();
const ALEXA = (() => {
const data = fs.readFileSync(ALEXA_PATH, 'utf8');
const lines = data.split('\n');
const result = [];
let cur = 1;
for (const line of lines) {
const ln = line.trim().toLowerCase();
if (ln.length === 0)
continue;
const items = ln.split(/\s*,\s*/);
assert(items.length === 2);
const [num, domain] = items;
const rank = parseInt(num, 10);
assert((rank >>> 0) === rank);
// No idea why alexa does this.
if (rank !== cur) {
assert(rank > cur);
console.error('Warning: rank inconsistency!');
console.error('Rank %d is missing.', cur);
cur = rank;
}
result.push(domain);
cur += 1;
}
assert(result.length === 1000000);
return result;
})();
const WORDS = (() => {
const data = fs.readFileSync(WORDS_PATH, 'utf8');
const lines = data.split('\n');
const result = [];
for (const line of lines) {
const word = line.trim();
if (util.isHNS(word))
result.push(word);
}
return result;
})();
fs.writeFileSync(
Path.resolve(__dirname, 'names', 'blacklist.json'),
JSON.stringify(BLACKLIST, null, 2) + '\n');
fs.writeFileSync(
Path.resolve(__dirname, 'names', 'custom.json'),
JSON.stringify(CUSTOM, null, 2) + '\n');
fs.writeFileSync(
Path.resolve(__dirname, 'names', 'values.json'),
JSON.stringify(VALUES, null, 2) + '\n');
fs.writeFileSync(
Path.resolve(__dirname, 'names', 'tld.json'),
JSON.stringify(TLD, null, 2) + '\n');
fs.writeFileSync(
Path.resolve(__dirname, 'names', 'cctld.json'),
JSON.stringify(CCTLD, null, 2) + '\n');
fs.writeFileSync(
Path.resolve(__dirname, 'names', 'gtld.json'),
JSON.stringify(GTLD, null, 2) + '\n');
fs.writeFileSync(
Path.resolve(__dirname, 'names', 'rtld.json'),
JSON.stringify(RTLD, null, 2) + '\n');
fs.writeFileSync(
Path.resolve(__dirname, 'names', 'alexa.json'),
JSON.stringify(ALEXA, null, 2) + '\n');
fs.writeFileSync(
Path.resolve(__dirname, 'names', 'words.json'),
JSON.stringify(WORDS, null, 2) + '\n');