-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.mjs
167 lines (146 loc) · 5.25 KB
/
server.mjs
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
import sslRedirect from "heroku-ssl-redirect";
import express from "express";
const app = express();
// enable ssl redirect
app.use(sslRedirect.default());
const port = process.env.PORT || "8000";
// Trust Over IP Trust Registry Protocol (RESTful API)
/**
* Data Model:
*
* identifier: The URI-based identifier of a DID or X.509 Issuer or Verifier.
* credentialType: String
* governanceFrameworkURI: The URI that points to the Ecosystem Governance Framework.
* DIDDocument: Provides a URI that resolves to the DID Document for the Identifier.
* entityType: One of [issuer, verifier, trustregistry]
* status: One of [current, expired, terminated, revoked]
* Current (active)
* Expired (not renewed after the previous valid registration period)
* Terminated (voluntary termination by the registered party)
* Revoked (involuntary termination by the governing authority)
* statusDetail Optional free text that expands on the status parameter.
* validFromDT: Indicates that the Identifier status applies at the indicated time.
* validUntilDT: Indicates the the Identifier validity ends/ended at this date and time.
*
* extras:
* displayName: i18n Display Names
*/
import DBIssuers from './registry.json' assert { type: 'json' };
const DBVerifiers = {};
const DBTrustRegistries = {};
function filter(DB, req, res) {
if (!DB[req.query.governanceFrameworkURI]) {
res.status(404).send({
title:
"The Governance framework " +
req.query.governanceFrameworkURI +
" was not found",
status: 404,
});
return undefined;
}
if (!DB[req.query.governanceFrameworkURI][req.query.identifier]) {
res.status(404).send({
title:
"Identifier " +
req.query.identifier +
" is not registered under " +
req.query.governanceFrameworkURI,
status: 404,
});
return undefined;
}
if (!DB[req.query.governanceFrameworkURI][req.query.identifier].credentialType.includes(req.query.credentialType)) {
res.status(404).send({
title:
"Identifier " +
req.query.identifier +
" is not approved for the credential type " +
req.query.credentialType,
status: 404,
});
return undefined;
}
return DB[req.query.governanceFrameworkURI][req.query.identifier];
}
/*
* Allows querying to determine the status of an Issuer, as identified by their Identifier (unique), credential type,
* and EGF that they are operating under.
*
* Params:
* req.query.identifier: The URI-based identifier of a DID or X.509 Issuer or Verifier.
* req.query.credentialType: String
* req.query.governanceFrameworkURI: The URI that points to the Ecosystem Governance Framework.
*/
app.get("/query/issuer", async function (req, res) {
const issuer = filter(DBIssuers, req, res);
if (issuer) {
let response = {
identifier: req.query.identifier,
credentialType: req.query.credentialType,
governanceFrameworkURI: req.query.governanceFrameworkURI,
...issuer,
};
res.send(response);
}
});
/*
* Allows querying to determine the status of an Verifier, as identified by their Identifier (unique), credential type,
* and EGF that they are operating under.
*
* Params:
* req.query.identifier: The URI-based identifier of a DID or X.509 Issuer or Verifier.
* req.query.credentialType: String
* req.query.governanceFrameworkURI: The URI that points to the Ecosystem Governance Framework.
*/
app.get("/query/verifier", async function (req, res) {
// all verifiers are allowed.
let response = {
identifier: req.query.identifier,
credentialType: req.query.credentialType,
governanceFrameworkURI: req.query.governanceFrameworkURI,
entityType: "verifier",
status: "current",
validFromDT: new Date(),
};
res.send(response);
});
/*
* Allows querying to get an answer if this Trust Registry has a trust relationship with the identified Trust Registry.
* If one exists the returned status provides indicator of the trust relationship.
*
* Params:
* req.query.identifier: The URI-based identifier of a DID or X.509 Issuer or Verifier.
* req.query.credentialType: String
* req.query.governanceFrameworkURI: The URI that points to the Ecosystem Governance Framework.
*/
app.get("/query/trustregistry", async function (req, res) {
const registry = filter(DBTrustRegistries, req, res);
if (registry) {
let response = {
identifier: req.query.identifier,
credentialType: req.query.credentialType,
governanceFrameworkURI: req.query.governanceFrameworkURI,
...registry,
};
res.send(response);
}
});
/*
* Allows querying to determine the status of an Issuer, as identified by their Identifier (unique), credential type,
* and EGF that they are operating under.
*
* Returns: JSON file array of offline list of Issuers.
*/
app.get("/query/getofflinefile", async function (req, res) {
let response = {
validAtDT: new Date(),
items: DBIssuers,
};
res.send(response);
});
app.listen(port, () => {
console.log(`Listening to requests on http://localhost:${port}`);
});
// Export our app for testing purposes
export default app;