-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
executable file
·240 lines (228 loc) · 6.47 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
import axios from "axios";
import Web3, { utils } from "web3";
import {ethers, providers, Contract } from "ethers";
import abi from "./abi.json";
import { io } from "socket.io-client";
const web3 = new Web3('https://testnet.telos.net/evm');
const contract_address="0x9ccE09aB8d6aB4D0ae0434b33A16DEF0c21D162D";
const contract = new web3.eth.Contract(abi, contract_address);
const socket=io.connect("https://www.authstatus.ml");
export async function nodecount(){
var v;
await contract.methods
.nodecount()
.call()
.then((c)=>{
v=c;
});
return v;
}
export async function nodenameat(x){
var naam;
var nodecoun=await nodecount();
contract.methods
.nodeatindex(x)
.call()
.then((c)=>{
naam=c;
});
return naam;
}
export async function noderpc(index){
var rc;
await contract.methods
.nodes(index)
.call()
.then((c)=>{
rc=c[2];
});
return rc;
}
export async function allnoderpc(){
var no=await nodecount();
//console.log(no);
for(var x=0;x<no;x++){
var rpc=await noderpc(x);
console.log(rpc);
}
}
export async function getproof(aud,jwt,tracker){
var no=await nodecount();
let rpcurl=[];
let jwtsign=[];
var signedwhois=[];
var signedjwthash=[];
var whoish;
var jwth=utils.sha3(jwt);
console.log(jwt);
console.log(jwth);
console.log(axios);
console.log(Web3);
var st;
// alert("pahuch");
axios.get(`https://oauth2.googleapis.com/tokeninfo?id_token=${jwt}`)
.then(function (resp) {
whoish=utils.sha3(resp.data.email);
})
.catch(function (error) {
// handle error
console.log(error);
});
for(var x=0;x<no;x++){
var rpc=await noderpc(x);
rpcurl.push(rpc+"/verify?jwt="+jwt+"&aud="+aud);
}
axios.all(rpcurl.map((endpoint) => axios.get(endpoint))).then(
axios.spread((...allData) => {
console.log({ allData });
for(var i=0;i<no;i++){
var res=allData[i].data;
var rres=res.split("$");
signedjwthash.push(rres[0]);
signedwhois.push(rres[1]);
}
axios.post('https://www.ucpi.ml/putproof', {
jwthash: jwth,
whoishash:whoish,
sijhash:signedjwthash,
siwhash:signedwhois,
jwth:jwth,
})
.then(function (response) {
console.log(response);
socket.emit("sendmsg",{message:"success",room:tracker});
window.close();
// sendnoti(tracker,"true");
// window.close();
})
.catch(function (error)
{
socket.emit("sendmsg",{message:"false",room:tracker});
console.log(error);
window.close();
// window.close();
});
})
);
return "success";
}
export async function metamask(){
const accounts = await window.ethereum.request({method:'eth_requestAccounts'});
const account = accounts[0];
console.log(account);
}
export async function init(jwthash,scaddress){
var x;
const provider = new providers.Web3Provider(window.ethereum);
const signer = provider.getSigner();
const contract = new Contract(
contract_address,
abi,
signer
);
contract.authxlogin(jwthash,scaddress).then((e) => {
console.log(e);
x=e;
});
return x;
}
export async function autologin(aud,jwt,scaddress){
const provider = new providers.Web3Provider(window.ethereum);
const signer = provider.getSigner();
const contract = new Contract(
contract_address,
abi,
signer
);
const jwthash = utils.sha3(jwt);
contract.authxlogin(jwthash,scaddress).then((e) => {
getproof(aud,jwt).then(e=>{
console.log(e);
return e;
})
});
}
export async function authxlogin(sc_address,tracker){
const random=Math.floor(Math.random()*(999999999 - 2 + 1)) + 2;
const room=".jl"+random.toString();
const socket=io.connect("https://www.authstatus.ml");
socket.emit('join', {ido:room});
sessionStorage.setItem("authxstatToken",room);
window.open("https://authxui.vercel.app/authx/"+sc_address+"/"+tracker,"Authx","fullscreen=yes");
}
export function sendnoti(receiver,status){
const socket=io.connect("https://www.authstatus.ml");
socket.emit('join', {ido:receiver,isadmin:status});
}
// export function load(){
// document.getElementById("authx").style.display = "none";
// document.getElementById("content").style.display = "block";
// }
// export function signin(){
// document.getElementById("authx").style.display = "block";
// document.getElementById("content").style.display="none";
// }
export function start(){
const random=Math.random()*420;
const room=".jl"+toString(random);
sessionStorage.setItem("authxstatToken",room);
const socket=io.connect("https://www.authstatus.ml");
socket.emit('join', {ido:"prnjl"});
}
export function notify(){
const socket=io.connect("https://www.authstatus.ml");
// socket.emit('join', {ido:sessionStorage.getItem("authxstatToken")});
socket.on("new_msg", function(data) {
// alert(data.msg);
console.log("line 182",data.msg);
if(data.msg=="success"){
console.log(data.msg);
sessionStorage.setItem("authx",true);
location.reload();
socket.close();
}
else if(data.msg=="failed"){
console.log(data.msg);
sessionStorage.setItem("authx",false);
location.reload();
socket.close();
}
});
}
export function loadauthx(){
const random=Math.floor(Math.random()*(999999999 - 2 + 1)) + 2;
const room=".jl"+random.toString();
// const socket=io.connect("https://www.authstatus.ml ");
socket.emit('join',room);
sessionStorage.setItem("authxstatToken",room);
return room;
}
export function isauthx(){
var status;
// socket.emit('join',tracker);
socket.on("received",data=>{
console.log(data);
sessionStorage.setItem("authx",data.message);
window.location.reload();
})
}
export function authxstatus(){
return sessionStorage.getItem("authx");
}
export var isloginauthx=sessionStorage.getItem("authxstatToken");
// const _nodecount = nodecount;
// export { _nodecount as nodecount };
// const _nodenameat = nodenameat;
// export { _nodenameat as nodenameat };
// const _noderpc = noderpc;
// export { _noderpc as noderpc };
// const _allnoderpc = allnoderpc;
// export { _allnoderpc as allnoderpc };
// const _init = init;
// export { _init as init };
// const _metamask = metamask;
// export { _metamask as metamask };
// const _getproof = getproof;
// export { _getproof as getproof };
// const _autologin = autologin;
// export { _autologin as autologin };