-
Notifications
You must be signed in to change notification settings - Fork 18
/
ui.js
93 lines (78 loc) · 2.15 KB
/
ui.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
var bkg = chrome.extension.getBackgroundPage();
$(document).ready(function() {
var DELETEABLE_CLASS_NAME = "deleteable";
/*
* Handle a click for the
*/
$("#touch").on("click", function(e) {
e.preventDefault();
bkg.handleButtonPress();
});
$("#empty").on("click", function(e) {
e.preventDefault();
bkg.emptykeyStore();
});
/*
* Write Keys to UI
*/
$("#private-attestation-key p").text(bkg.getPrivateAttestationKey());
$("#public-attestation-key p").text(bkg.getPublicAttestationKey());
$("#attestation-certificate p").text(bkg.getAttestationCertificate());
/*
* Attach show/hide handlers
*/
$("#meta > div a").on("click", function(e) {
e.preventDefault();
if ($(this).hasClass("show")) {
$(this).parent().parent().find("p").show();
$(this).removeClass("show");
$(this).text("hide");
} else {
$(this).parent().parent().find("p").hide();
$(this).addClass("show");
$(this).text("show");
}
});
/**
* @param keys
*/
var updateKeyList = function (keys) {
var keysUi = $("#keys");
if (jQuery.isEmptyObject(keys)) {
$("#nokeys").show();
} else {
$("#nokeys").hide();
}
/*
* Mark all keys as deleteable first
*/
keysUi.find(".key").addClass(DELETEABLE_CLASS_NAME);
for (var key in keys) {
var keyUi = keysUi.find("#" + key);
var keyO = keys[key];
if (keyUi.length > 0) {
/*
* Key already exists remove deleteable marker
*/
keyUi.removeClass(DELETEABLE_CLASS_NAME);
} else {
/*
* Key doesn't exist in UI. Create!
*/
keysUi.append("<div id=\"key\" class=\"key\"><h4>Key Handle <strong>" + keyO.keyHandle + "</strong><br>" + keyO.generated + "</h4><h5>App ID <strong>" + keyO.appId + "</strong></h5><h6>Public Key:</h6><p>" + keyO.public + "</p><h6>Private Key:</h6><p>" + keyO.private + "</p><h6>Counter:</h6><p>" + keyO.counter + "</p></div>")
}
}
/*
* Remove nodes marked as deleteable
*/
keysUi.find("." + DELETEABLE_CLASS_NAME).remove();
};
/*
* Poll keystore for new key
*/
var timer;
(function updateUI(){
updateKeyList(bkg.getKeyStore());
timer = window.setTimeout(updateUI, 1200);
})();
});