File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import Cryptr from 'cryptr' ;
2+
3+ const cryptr = new Cryptr ( 'insert secret key here' ) ;
4+
5+ export function encrypt ( plaintext : string ) {
6+ return cryptr . encrypt ( plaintext ) ;
7+ }
8+
9+ export function decrypt ( ciphertext : string ) {
10+ return cryptr . decrypt ( ciphertext ) ;
11+ }
12+
13+ const tokens = [ '' ] ;
14+
15+ export async function getUserData ( token : string ) {
16+ const userDataURL = new URL ( `https://auth.hackclub.com/api/v1/me` ) ;
17+ const userDataRes = await fetch ( userDataURL , {
18+ method : 'GET' ,
19+ headers : {
20+ Authorization : `Bearer ${ token } `
21+ }
22+ } ) ;
23+
24+ if ( ! userDataRes . ok ) {
25+ throw new Error ( 'Failed to fetch user data' ) ;
26+ }
27+
28+ const userDataJSON = await userDataRes . json ( ) ;
29+
30+ return userDataJSON . identity ! ;
31+ }
32+
33+ const countries : Record < string , number > = { } ;
34+
35+ for ( let i = 0 ; i < tokens . length ; i ++ ) {
36+ try {
37+ const token = decrypt ( tokens [ i ] ) ;
38+ const userData = await getUserData ( token ) ;
39+ const { addresses } = userData ;
40+ const address = addresses ?. find ( ( address : { primary : boolean } ) => address . primary ) ;
41+ console . log ( 'Address' , i + '/' + tokens . length + ':' , address . country ) ;
42+
43+ countries [ address . country as string ] = ( countries [ address . country as string ] ?? 0 ) + 1 ;
44+ } catch {
45+ console . warn ( 'Failed: user ' + i ) ;
46+ }
47+ }
48+
49+ console . log ( '\n' ) ;
50+ console . log ( countries ) ;
You can’t perform that action at this time.
0 commit comments