-
Notifications
You must be signed in to change notification settings - Fork 2
/
common.js
233 lines (216 loc) · 8.06 KB
/
common.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
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
/* globals omitTerms, respecConfig, $, require */
/* exported linkCrossReferences, restrictReferences, fixIncludes */
var vcwg = {
// Add as the respecConfig localBiblio variable
// Extend or override global respec references
localBiblio: {
"VC-SPECS": {
title: "Verifiable Credential Specifications Directory",
href: "https://w3c.github.io/vc-specs-dir/",
authors: [
"Manu Sporny"
],
status: "ED",
publisher: "W3C Verifiable Credentials Working Group"
},
"STRING-META": {
title: "Strings on the Web: Language and Direction Metadata",
href: "https://www.w3.org/TR/string-meta/",
authors: [
"Addison Phillips",
"Richard Ishida"
],
status: "WD",
publisher: "Internationalization Working Group"
},
"EBSI": {
title: "EBSI W3C Verifiable Credentials (VCs) and W3C Verifiable Presentations (VPs)",
href: ["https://ec.europa.eu/digital-building-blocks/wikis/display/EBSIDOC/Verifiable+Attestation", "https://ec.europa.eu/digital-building-blocks/wikis/display/EBSIDOC/Issuers+trust+model+-+Accreditation+of+Issuers"],
authors: "European Blockchain Services Infrastructure (EBSI)",
status: "Developers hub materials",
publisher: "European Commission"
},
"VC-DATA-INTEGRITY": {
title: "Verifiable Credential Data Integrity",
href: "https://www.w3.org/TR/vc-data-integrity/",
authors: [
"Manu Sporny",
"Dave Longley",
"Mike Prorock"
],
status: "WD",
publisher: "Verifiable Credentials Working Group"
},
"VC-CONTROLLER-DOCUMENT": {
title: "Verifiable Credential Controller Document",
href: "https://w3c.github.io/vc-controller-document/",
authors: [
"Manu Sporny",
"Dave Longley",
"Markus Sabadello",
"Drummond Reed",
"Orie Steele",
"Christopher Allen",
"Michael B. Jones"
],
status: "ED",
publisher: "Verifiable Credentials Working Group"
},
'RDF-NORMALIZATION': {
title: 'RDF Dataset Normalization',
href: 'http://json-ld.github.io/normalization/spec/',
authors: ['Dave Longley', 'Manu Sporny'],
status: 'CG-DRAFT',
publisher: 'Credentials W3C Community Group'
},
'DEMOGRAPHICS': {
title: 'Simple Demographics Often Identify People Uniquely',
href: 'https://dataprivacylab.org/projects/identifiability/paper1.pdf',
authors: ['Latanya Sweeney'],
publisher: 'Data Privacy Lab'
},
"NIST-SP-800-57-Part-1": {
title: "Recommendation for Key Management: Part 1 – General",
authors: ["Elaine Barker"],
date: "May 2020",
publisher: "National Institute of Standards and Technology",
href: "https://doi.org/10.6028/NIST.SP.800-57pt1r5"
},
'VC-IMP-GUIDE': {
title: 'Verifiable Credentials Implementation Guidelines 1.0',
href: 'https://w3c.github.io/vc-imp-guide/',
authors: ['Andrei Sambra', 'Manu Sporny'],
status: 'ED',
publisher: 'Credentials Community Group'
},
'VC-JSON-SCHEMA': {
title: 'Verifiable Credentials JSON Schema Specification',
href: 'https://www.w3.org/TR/vc-json-schema/',
authors: ['Gabe Cohen', 'Orie Steele'],
status: 'FPWD',
publisher: 'W3C Verifiable Credentials Working Group'
},
'JSON-LD': {
title: 'JSON-LD 1.1: A JSON-based Serialization for Linked Data',
href: 'https://www.w3.org/TR/json-ld11/',
authors: ['Gregg Kellogg', 'Manu Sporny', 'Dave Longley', 'Markus Lanthaler', 'Pierre-Antoine Champin', 'Niklas Lindström'],
status: 'WD',
publisher: 'W3C JSON-LD 1.1 Working Group'
},
'VC-SPECS': {
title: 'Verifiable Credentials Specifications Directory',
href: 'https://w3c.github.io/vc-specs-dir/',
authors: ['Manu Sporny'],
status: 'ED',
publisher: 'W3C Verifiable Credentials Working Group'
},
'PRES-EX': {
title: 'Presentation Exchange 2.0.0',
href: 'https://identity.foundation/presentation-exchange/spec/v2.0.0/',
authors: ['Daniel Buchner', 'Brent Zundel', 'Martin Riedel', 'Kim Hamilton Duffy'],
status: 'DIF Ratified Specification',
publisher: 'Decentralized Identity Foundation'
},
'OHTTP': {
title: 'Oblivious HTTP ',
href: 'https://datatracker.ietf.org/doc/html/draft-ietf-ohai-ohttp',
authors: ['Martin Thomson', 'Christopher A. Wood'],
status: 'Working Group Draft',
publisher: 'IETF Oblivious HTTP Application Intermediation'
}
}
};
require(["core/pubsubhub"], (respecEvents) => {
"use strict";
respecEvents.sub('end-all', (message) => {
console.log("END EVENT", message);
// remove data-cite on where the citation is to ourselves.
const selfDfns = document.querySelectorAll("dfn[data-cite^='" + respecConfig.shortName.toUpperCase() + "#']");
for (const dfn of selfDfns) {
delete dfn.dataset.cite;
}
// Update data-cite references to ourselves.
const selfRefs = document.querySelectorAll("a[data-cite^='" + respecConfig.shortName.toUpperCase() + "#']");
for (const anchor of selfRefs) {
anchor.href= anchor.dataset.cite.replace(/^.*#/,"#");
delete anchor.dataset.cite;
}
});
});
// Removes dfns that aren't referenced anywhere in the spec.
// To ensure a definition appears in the Terminology section, use
// and link to it!
// This is triggered by postProcess in the respec config.
function restrictRefs(config, document){
// Get set of ids internal dfns referenced in the spec body
const internalDfnLinks = document.querySelectorAll("a.internalDFN");
let internalDfnIds = new Set();
for (const dfnLink of internalDfnLinks) {
const dfnHref = dfnLink.href.split("#")[1];
internalDfnIds.add(dfnHref);
}
// Remove unused dfns from the termlist
const termlist = document.querySelector(".termlist");
const linkIdsInDfns = [];
for (const child of termlist.querySelectorAll("dfn")){
if (!internalDfnIds.has(child.id)){
let dt = child.closest("dt");
let dd = dt.nextElementSibling;
// Get internal links from dfns we're going to remove
// because these show up in the dfn-panels later and then
// trigger the local-refs-exist linter (see below)
const linksInDfn = dd.querySelectorAll("a.internalDFN");
for (link of linksInDfn) {
linkIdsInDfns.push(link.id);
}
termlist.removeChild(dt);
termlist.removeChild(dd);
}
}
// Remove unused dfns from the dfn-panels
// (these are hidden, but still trigger the local-refs-exist linter)
// (this seems like a hack, there's probably a better way to hook into respec
// before it gets to this point)
const dfnPanels = document.querySelectorAll(".dfn-panel");
for (const panel of dfnPanels) {
if (!internalDfnIds.has(panel.querySelector(".self-link").href.split("#")[1])){
panel.parentNode.removeChild(panel);
}
// Remove references to dfns we removed which link to other dfns
const panelLinks = panel.querySelectorAll("li a");
for (const link of panelLinks) {
if (linkIdsInDfns.includes(link.href.split("#")[1])) {
link.parentNode.removeChild(link);
}
}
}
}
function _esc(s) {
return s.replace(/&/g,'&')
.replace(/>/g,'>')
.replace(/"/g,'"')
.replace(/</g,'<');
}
function reindent(text) {
// TODO: use trimEnd when Edge supports it
const lines = text.trimRight().split("\n");
while (lines.length && !lines[0].trim()) {
lines.shift();
}
const indents = lines.filter(s => s.trim()).map(s => s.search(/[^\s]/));
const leastIndent = Math.min(...indents);
return lines.map(s => s.slice(leastIndent)).join("\n");
}
function updateExample(doc, content) {
// perform transformations to make it render and prettier
return _esc(reindent(unComment(doc, content)));
}
function unComment(doc, content) {
// perform transformations to make it render and prettier
return content
.replace(/<!--/, '')
.replace(/-->/, '')
.replace(/< !\s*-\s*-/g, '<!--')
.replace(/-\s*- >/g, '-->')
.replace(/-\s*-\s*>/g, '-->');
}