-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
73 lines (53 loc) · 1.94 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
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for
* license information.
*/
'use strict';
var http = require('http');
const KeyVault = require('@azure/keyvault');
const MsRestAzure = require('@azure/ms-rest-nodeauth');
const Azure = require("@azure/storage-blob");
const base64url = require('base64url');
const CryptoJS = require('crypto-js');
const Agent = require('./agent.js');
async function main() {
try {
// when the server first starts, register a DID for the enterprise
await Agent.EnsureDidRegistered();
} catch (err) {
console.log('Error while setting up enterprise agent: ' + err);
return;
}
// listen for incoming requests for verifiable claims
var server = http.createServer(async function(request, response) {
console.log(`Request received at ${Date.now()}`);
try {
// create the contents of the claim (hard-coded for now)
const credential = {
"@context": ["https://schema.org/"],
"@type": ["Diploma"],
"credentialSubject": {
"student_name": "Alice Smith",
"graduation_year": "2013",
"university_name": "University of California, Los Angeles"
}
};
// Form the claim as a verifiable credential in JWT format
const claimDetails = await Agent.GenerateVerifiableCredential(credential);
// return the claim to the browser
response.writeHead(200, {"Content-Type": "text/plain"});
response.end(JSON.stringify(claimDetails));
} catch (err) {
console.log(err);
// return the claim to the browser
response.writeHead(200, {"Content-Type": "text/plain"});
response.end(JSON.stringify(err.toString()));
}
});
// Start the server
var port = process.env.PORT || 1337;
server.listen(port);
console.log("Server running at http://localhost:%d", port);
}
main();