-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathverifiable_claim.html
305 lines (272 loc) · 8.92 KB
/
verifiable_claim.html
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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function load() {
var uname = "";
var xhttp = new XMLHttpRequest();
var params = "username=" + document.getElementById('username').value + "&pwd=" + document.getElementById('pwd').value;
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
window.location.replace("http://localhost:9091/home/did?username=" + document.getElementById('username').value + "&page=DID");
}
};
xhttp.open("POST", "http://localhost:9091/authenticate", true);< !DOCTYPE html >
<html>
<head>
<script type="text/javascript">
function didFunction() {
window.location.replace("http://localhost:9091/home/did?username=EMPTYUNAME");
}
function vcFunction() {
window.location.replace("http://localhost:9091/home/vc?username=EMPTYUNAME&did=DIDMID");
}
function vcRequestFunction() {
}
</script>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<script src="http://localhost:8080/jsencrypt.js"></script>
<script src="http://localhost:8080/browser-aes.js"></script>
<script type="text/javascript">
function showVC(dt){
var w = 400;
var h = 600;
var left = (screen.width/2)-(w/2);
var top = (screen.height/2)-(h/2);
var xhttp = new XMLHttpRequest();
var vc = "";
var params = "command=cmd3&id=" + dt;
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
console.log("response :" + this.responseText);
if (this.responseText == "no-vc-for-this-did") {
vc = 'Verifiable credential data could not be found.';
} else {
vc = this.responseText;
}
var win = window.open('', 'Verifiable credential of did:ethr:' + dt, 'toolbar=no, title=\'Verifiable Credential\' location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left);
var doc = win.document.open();
}
doc.write('<html><body>' + vc + '</body></html>');
doc.close();
};
xhttp.open("POST", "http://localhost:9091/api", true);
xhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhttp.send(params);
}
function decryptRSA(encrypted) {
var decrypt = new JSEncrypt();
decrypt.setPrivateKey(document.getElementById('privkey').value);
var uncrypted = decrypt.decrypt(encrypted);
return uncrypted;
}
function send(encryptedval) {
var xhttp = new XMLHttpRequest();
var urlEncodedDataPairs = [];
console.log('encryptedval:' + encryptedval);
var params = "did=" + document.getElementById('didTxt').value + "&encryptedval=" + encryptedval + "&command=encresponse";
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
if (this.responseText != 'none') {
var res = this.responseText.split('|||');
var item = res[1];
var vcTxt = res[2];
var res2 = item.split(",");
var didmidVC = res2[0];
var didVC = res2[1];
var nameVC = res2[3];
var issuerVC = res2[2];
var xhttp = new XMLHttpRequest();
var params = "command=cmd2&did=" + didmidVC + "&didVC=" + didVC + "&issuerVC=" + issuerVC + "&nameVC=" + nameVC + "&vcTxt=" + vcTxt;
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
console.log("response :" + this.responseText);
if (this.responseText == "vc-already-exist") {
alert('Verifiable credentials are already up to date.');
} else {
document.getElementById("vctable").innerHTML = this.responseText;
}
}
};
xhttp.open("POST", "http://localhost:9091/api", true);
xhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhttp.send(params);
} else {
alert('Could not find any verifiable credentials.');
}
}
};
xhttp.open("POST", "http://localhost:9090/api", true);
xhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhttp.send(params);
}
$(document).ready(function() {
$("#submitRequest").click(function () {
$.post($('#issuerURL').val(),
{
command: 'requestvc',
did: $('#didTxt').val()
},
function (data, status) {
unencrypted = decryptRSA(data.trim());
if (!(typeof unencrypted === "boolean")) {
send(unencrypted);
}
});
});
});
</script>
<script>
function startRead() {
var file = document.getElementById('file-input').files[0];
if(file){
out = getAsText(file);
}
}
function getAsText(readFile) {
var reader = new FileReader();
reader.readAsText(readFile, "UTF-8");
reader.onprogress = updateProgress;
reader.onload = loaded;
reader.onerror = errorHandler;
}
function updateProgress(evt) {
}
function loaded(evt) {
var fileString = evt.target.result;
document.getElementById('privkey').value = fileString;
console.log("privkey: " + document.getElementById('privkey').value);
}
function errorHandler(evt) {
if(evt.target.error.name == "NotReadableError") {
console.log("privkey: The file could not be read");
}
}
</script>
</head>
<body bgcolor="lightblue">
<table border="0" width="600">
<tr>
<td>
<table>
<tr>
<td>
<a href="javascript:void(0);" id="logout" onclick="didFunction();">DID</a>
</td>
</tr>
<tr>
<td>
</td>
</tr>
<tr>
<td>
<a href="javascript:void(0);" id="logout" onclick="vcFunction();">VC</a>
</td>
</tr>
<tr>
<td>
</td>
</tr>
<tr>
<td>
<a href="http://localhost:9091/logout?username=EMPTYUNAME" id="logout" download>Logout</a>
</td>
</tr>
</tr>
</table>
</td>
<td>
<table>
<tr>
<tr>
<td>
<table>
<tr>
<td> Your Credentials Repository : </td>
<td>https://localhost:9091/vc/</td>
<input type="text" id="didTxt" name="didTxt" hidden value="DIDTXTVAL"></input>
</tr>
</table>
</tr>
<tr>
<td>
<h3>Your List of Verifiable Credentials </h3>
</td>
</tr>
<tr>
<td>
<div id="vctable">
VCTABLE
</div>
</td>
</tr>
<tr>
<td>
<table>
<tr>
<td>Issuer URL : </td>
<td><input type="text" id="issuerURL" name="issuerURL" size=20 value="http://localhost:9090/api"></input>
</td>
</tr>
<tr>
<td>Your private key file : </td>
<td><input type="file" id="file-input" name="file-input" size=20 onchange="startRead()"></input></td>
<td> </td>
<input type="text" id="privkey" name="privkey" style="display:none">
</tr>
<tr>
<td><input type="button" id="submitRequest" value="Request"></input></td>
<td> </td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
xhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhttp.send(params);
};
</script>
</head>
<body>
<h2>Verifiable Claim</h2>
<body bgcolor="lightblue">
<table>
<tr>
<td>
<label for="usernameLabel">User Name:</label><br/>
<!--<input type="text" id="username" name="username" style="display:none">-->
</td>
<td>
<input type="text" id="username" name="username">
</td>
</tr>
<tr>
<td height="10"></td>
</tr>
<tr>
<td>
<label for="privkey">Password:</label>
</td>
<td>
<input type="password" id="pwd" name="pwd">
</td>
</tr>
<tr>
<td height="10"></td>
</tr>
<tr>
<td>
<input type="button" value="Submit" onclick="load()">
</td>
</tr>
</table>
<p id="demo"></p>
</body>
</html>