-
Notifications
You must be signed in to change notification settings - Fork 38
/
blockchain-certificate.html
178 lines (156 loc) · 5.01 KB
/
blockchain-certificate.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
<link rel="import" href="/components/polymer/polymer.html">
<link rel="import" href="/components/iron-ajax/iron-ajax.html">
<link rel="import" href="common-styles.html">
<!--
`blockchain-certificate`
Displays a rendered Blockchain Certificate
@demo demo/index.html
-->
<dom-module id="blockchain-certificate">
<template>
<style include="common-styles"></style>
<iron-ajax
auto
url=[[href]]
handle-as="text"
params='{"format":"json"}'
on-response="_handleResponse"
on-error="_handleError"
debounce-duration="300">
</iron-ajax>
<template is="dom-if" if=[[isLoading]]>
<h1>Loading...</h1>
</template>
<template is="dom-if" if=[[isErrored]]>
<h1>[[_status]]</h1>
<a href=[[href]]>View Certificate</a>
</template>
<template is="dom-if" if=[[hasCertificateData]]>
<section class="certificate-image"><img src=[[_certificateImage]] /></section>
<section class="headers">
<h1 class="recipient">[[_recipient]]</h1>
<h2 class="title">[[_title]]</h2>
<h3 class="subtitle">[[_subtitle]]</h3>
</section>
<section class="description">
<p>[[_description]]</p>
</section>
<section class="signatures">
<img src=[[_signatureImage]] />
</section>
<section class="seal">
<img src=[[_sealImage]] />
</section>
</template>
</template>
<script src="./verifier.js"></script>
<script>
Polymer({
is: 'blockchain-certificate',
properties: {
/* The URL of the certificate you wish to display. */
href: {
type: String,
value: 'blockchain-certificate',
// observer: '_hrefChanged'
},
/* True while we're loading the certificate at the given href. */
isLoading: {
type: Boolean,
value: true,
readOnly: true
},
/* True if we've encountered an error trying to download or parse the certificate at the given href. */
isErrored: {
type: Boolean,
value: false,
readOnly: true
},
/* True if we've successfully loaded & parsed certificate data from the given href. False otherwise. */
hasCertificateData: {
type: Boolean,
value: false,
readOnly: true
},
/* The contents of the certificate at the specified href. */
certificateData: {
type: String,
readOnly: true
},
/* A short explanation of the status of the web component */
_status: {
type: String,
readOnly: true
},
//
// Private properties
//
/* Image attached to the certificate object. */
_certificateImage: {
type: String,
readOnly: true
},
/* The first & last name of the recipient */
_recipient: {
type: String,
readOnly: true
},
/* Title on the certificate */
_title: {
type: String,
readOnly: true
},
/* Subtitle on the certificate */
_subtitle: {
type: String,
readOnly: true
},
/* Description on the certificate */
_description: {
type: String,
readOnly: true
},
/* Image on the assertion. Typically, this is a picture of a signature. */
_signatureImage: {
type: String,
readOnly: true
},
/* Image of the issuing institution. Typically, this is the official seal of the issuing institution. */
_sealImage: {
type: String,
readOnly: true
}
},
_handleResponse: function(event) {
try {
// We need to save the string response, because older validation methods require us to validate the unchanged file.
const stringResponse = event && event.detail && event.detail.response;
this._setCertificateData(stringResponse);
const certJson = JSON.parse(stringResponse);
const cert = Verifier.Certificate.parseJson(certJson);
this._setHasCertificateData(true);
this._set_certificateImage(cert.certificateImage);
this._set_recipient(cert.name);
this._set_title(cert.title);
this._set_subtitle(cert.subtitle);
this._set_description(cert.description);
this._set_signatureImage(cert.signatureImage[0].image);
this._set_sealImage(cert.sealImage);
} catch (e) {
this._setIsLoading(false);
this._setHasCertificateData(false);
this._setIsErrored(true);
this._set_status("Referenced certificate doesn't appear to be valid.");
} finally {
this._setIsLoading(false);
}
},
_handleError: function() {
this._setIsLoading(false);
this._setHasCertificateData(false);
this._setIsErrored(true);
this._set_status('Failed to load certificate at URL.');
}
});
</script>
</dom-module>