-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
282 lines (152 loc) · 6.5 KB
/
index.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
274
275
276
277
278
279
280
281
const ethers = require('ethers');
const {render} = require('ejs');
const express = require('express');
const url = require('url');
const fetch = (...args) => import('node-fetch').then(({default: fetch}) => fetch(...args));
const {default: Resolution} = require('@unstoppabledomains/resolution');
const resolution = new Resolution();
require('dotenv').config()
const cors = require("cors");
const { env } = require('process');
// const ENS = require('@ensdomains/ensjs');
// const provider = new ethers.providers.JsonRpcProvider(process.env.Infura_Id);
// const ENSInstance = new ENS()
app = express();
app.use(cors());
app.set('view engine','ejs');
app.use(express.static('public'));
app.use(express.urlencoded({extended:true}))
app.get("/", (req,res)=>{
res.send('Welcome to Ens Search!');
})
app.get("/api/:id",async (req,res)=>{
var ensNameValue = req.url;
var ensNameSlice;
console.log(ensNameValue)
// check if url given is null or is it a address else assaign ensname to go pass througth the .eth store
try{
if(ensNameValue && !ensNameValue.includes('.eth') && ensNameValue.length>42){
var ens = ensNameValue.slice(5,ensNameValue.length);
console.log(ens);
let value = await provider.lookupAddress(ens);
if(value){
value = ensNameSlice;
console.log("value:",ensNameSlice);
}
} else {
ensNameSlice = ensNameValue.slice(5,ensNameValue.length);
console.log(ensNameSlice);
}
// if ens name not null it will pass through this if cluase and it will only pass through if it is ens name.
// if address in the above clause doesnt resolve else cluase will give ens not registerted answer.
if(ensNameSlice != null && (ensNameSlice.includes('.eth') || !ensNameSlice.includes('0x'))){
var address,profile,ipfs,email,website,twitter,discord,github,telegram,description,reddit;
// get resolver from the obtained ens name now and process continues.
const result = await provider.getResolver(ensNameSlice);
if(result!= null){
let address1 = result.getAddress();
let profile = result.getAvatar();
let ipfs1 = result.getContentHash();
let email1 = result.getText("email");
let website1 = result.getText("url");
let twitter1 = result.getText("com.twitter");
let discord1 = result.getText('com.discord');
let github1 = result.getText('com.github');
let telegram1 = result.getText('org.telegram');
let description1 = result.getText('description');
let reddit1 = result.getText('com.reddit');
Promise.all([address1,email1,profile,ipfs1,website1,twitter1,discord1,github1,telegram1,description1,reddit1]).then( e=>{
res.json({
'Name':ensNameSlice,
'Address':e[0],
'Email': e[1],
'Profile': e[2],
'Ipfs':e[3],
'Website': e[4],
'Twitter': e[5],
'Discord': e[6],
'Github':e[7],
'Telegram': e[8],
'Description':e[9],
'Reddit': e[10]
})
}
)
} else {
console.log('resolver null')
res.json({'Message':'ENS Name Not Registered'})
}
} else {console.log('resolver null')
res.json({'Message':'ENS Name Not Registered or Not Found'})
}
}catch{
res.json({'Message':'ENS Name Not Registered or Not Found'})
}}
)
// here uns resolver is used
app.get("/apiuns/:id",async(req,res)=>{
let _ethValue = req.url.slice(8,req.url.length);
if(_ethValue.includes('.zil')){
resolve(_ethValue, 'ZIL');
} else {
resolve(_ethValue, 'ETH');
}
function resolve(domain, currency) {
resolution
.addr(domain, currency)
.then((address) => {
console.log(domain, 'resolves to', address)
if(address){
fetch(`https://resolve.unstoppabledomains.com/metadata/${domain}`, {
method: "GET",
headers: {
'Authorization': process.env.auth,
"accept": "application/json",
}
})
.then(response => response.json())
.then(async(_response) =>{
console.log(_response)
return res.json({
'address':address,
'err':false,
'Exists':true,
'data':_response,
})
})
.catch(err => res.json({"error":err.code}));
} else{
return req.json({"info":"address not set"});
}
})
.catch(err=>{res.json({err})});
}
// for 404 error pages
});
app.get("/apiresolver/:id",async (req,res)=>{
let _ethValue = req.url.slice(13,req.url.legth);
console.log(_ethValue)
// const ensnames = await ENSInstance.setProvider(provider);
// console.log(ensnames);
if (_ethValue){
try{ fetch(
`https://resolve.unstoppabledomains.com/reverse/${_ethValue}`,
{
method: 'GET',
headers: {
Authorization: env.auth
}}
).then(e=>e.json()).then(e=> {res.json({e})
console.log(e)}
)
}
catch{
console.log(err);
}}
})
app.use((req,res)=>{
res.render('404')
})
app.listen(process.env.PORT || 3000,()=>{
console.log('Porrt listening on 3000 port')
})