-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
97 lines (85 loc) · 2.44 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
import fs from "fs";
import axiosDelimiter from "./axiosDelimiter.js";
import Web3 from "web3";
const web3 = new Web3();
import scholars from "./scholars.js";
let result = [];
//Generate Random Message
async function getRandMessage() {
const data = {
operationName: "CreateRandomMessage",
query: "mutation CreateRandomMessage {\ncreateRandomMessage\n}\n",
variables: {},
};
return axiosDelimiter
.post("https://axieinfinity.com/graphql-server-v2/graphql", data)
.then((res) => {
return res.data.data.createRandomMessage;
})
.catch((err) => {
console.log(err);
});
}
//Generate Signature Message
function getSignMessage(randMessage, privateKey) {
let hexSignature = web3.eth.accounts.sign(randMessage, privateKey);
return hexSignature.signature;
}
//Generate Access Token
async function getAccessToken(accountAddress, randMessage, hexSignature) {
const data = {
operationName: "CreateAccessTokenWithSignature",
variables: {
input: {
mainnet: "ronin",
owner: accountAddress,
message: randMessage,
signature: hexSignature,
},
},
query:
"mutation CreateAccessTokenWithSignature($input: SignatureInput!) {\n createAccessTokenWithSignature(input: $input) {\n newAccount\n result\n accessToken\n __typename\n }\n}\n",
};
return axiosDelimiter
.post("https://axieinfinity.com/graphql-server-v2/graphql", data)
.then((res) => {
return res.data.data.createAccessTokenWithSignature.accessToken;
})
.catch((err) => {
console.log(err);
});
}
//Generate the results
async function getResults() {
let total = scholars.length;
let processed = 0;
const randMessage = await getRandMessage();
scholars.map(async (scholar) => {
const hexSignature = getSignMessage(randMessage, scholar.private_key);
scholar = {
...scholar,
access_token: await getAccessToken(
scholar.ronin_address,
randMessage,
hexSignature
),
};
result.push(scholar);
processed++;
if (processed === total) {
saveFile();
}
});
}
//Saves the file as result.json
function saveFile() {
let jsonContent = JSON.stringify(result, null, "\t");
fs.writeFile("result.json", jsonContent, "utf8", (err) => {
if (err) {
console.log("An error has occured");
return console.log(err);
}
return console.log("JSON file has been saved - result.json");
});
}
getResults();