forked from decentralized-identity/JWS-Test-Suite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
evaluate.js
123 lines (111 loc) · 3.43 KB
/
evaluate.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
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
console.log("\n🔎 Preparing evaluation report...\n");
const path = require("path");
const fs = require("fs");
const { verify } = require("./implementations/transmute/cli");
const verifyRSA = require("./implementations/spruce/verify");
const implementationsReport = path.join(__dirname, "./data/implementations");
const buildImplementationsIndex = () => {
const implementationIndex = {};
const imps = fs.readdirSync(implementationsReport);
imps.forEach((imp) => {
if (imp.includes("index.json")) {
return;
}
const implementationVectorsPath = path.join(
__dirname,
"./data/implementations/",
imp
);
const implementationVectors = fs.readdirSync(implementationVectorsPath);
implementationIndex[imp] = {};
implementationVectors.forEach(async (v) => {
if (!v.endsWith(".json")) {
return;
}
if (v.includes("test.json")) {
return;
}
if (v.includes("test.verification.json")) {
return;
}
const vectorPath = path.resolve(
__dirname,
"./data/implementations/",
imp,
v
);
const vectorFile = fs.readFileSync(vectorPath).toString();
try {
const parsedVector = JSON.parse(vectorFile);
implementationIndex[imp] = {
...implementationIndex[imp],
[v]: parsedVector,
};
} catch (e) {
console.warn("Unable to parse: " + vectorPath);
}
});
});
return implementationIndex;
};
const extendIndexWithEvaluations = async (index) => {
const implementations = Object.keys(index);
for (const implementation of implementations) {
const vectors = Object.keys(index[implementation]);
for (const vector of vectors) {
let format;
let vectorContent;
if (vector.includes("credential")) {
format = vector.includes("vc-jwt") ? "vc-jwt" : "vc";
if (!format.includes("jwt")) {
vectorContent = index[implementation][vector];
} else {
vectorContent = index[implementation][vector].jwt;
}
} else {
format = vector.includes("vp-jwt") ? "vp-jwt" : "vp";
if (!format.includes("jwt")) {
vectorContent = index[implementation][vector];
} else {
vectorContent = index[implementation][vector].jwt;
}
}
const isRSA =/-rsa\d/.test(vector);
const verification = isRSA
? await verifyRSA(vectorContent, format)
: await verify(vectorContent, format);
index[implementation][vector] = {
vector: format,
vectorContent,
verification,
};
}
}
return index;
};
(async () => {
const implementationIndex = buildImplementationsIndex();
const implementationResults = await extendIndexWithEvaluations(
implementationIndex
);
const indexOutputPath = path.join(
__dirname,
"./data/implementations/index.json"
);
// Sanitize results for stringification.
// https://github.com/transmute-industries/verifiable-data/issues/120
for (const imp in implementationResults) {
for (const k in implementationResults[imp]) {
delete implementationResults[imp][k].verification.error
delete implementationResults[imp][k].verification.credentials
delete implementationResults[imp][k].verification.presentation
}
}
fs.writeFileSync(
indexOutputPath,
JSON.stringify(implementationResults, null, 2)
);
})().catch((e) => {
console.error(e)
process.exit(1)
});