-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbackground.js
56 lines (46 loc) · 1.37 KB
/
background.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
var account = Orbs.createAccount();
console.log("New account: " + account.publicKey);
var client = new Orbs.Client('https://validator.orbs-test.com/vchains/6666', 6666, 'TEST_NET');
chrome.runtime.onMessage.addListener(
function (request, sender, sendResponse) {
console.log(request.url)
//console.log(sender)
//console.log(sendResponse)
if (request.action == "verify") {
const body = '{"url":"' + request.url + '"}'
const xhr = new XMLHttpRequest();
xhr.open('POST', 'http://10.240.2.76:5678');
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.onload = async function () {
if (xhr.status === 200) {
const phash = xhr.responseText;
const r = await query(phash)
sendResponse(r)
}
else {
sendResponse({ ok: false })
}
};
xhr.send(body);
}
return true
});
async function query(phash) {
const q = client.createQuery(
account.publicKey,
'registry',
'verify',
[Orbs.argString(phash)]
)
const r = await client.sendQuery(q)
if (r.executionResult != "ERROR_SMART_CONTRACT") {
const jo = JSON.parse(r.outputArguments[0].value);
return { ok: true, source: jo }
}
return { ok: false }
}
chrome.browserAction.onClicked.addListener(function (tab) {
chrome.tabs.executeScript({
file: "/inject.js"
});
});