@blockcerts/blockcerts-verifier 1.37.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.eslintrc.js ADDED
@@ -0,0 +1,27 @@
1
+ module.exports = {
2
+ root: true,
3
+ parser: '@typescript-eslint/parser',
4
+ plugins: [
5
+ '@typescript-eslint',
6
+ ],
7
+ extends: [
8
+ 'standard-with-typescript',
9
+ 'eslint:recommended',
10
+ 'plugin:@typescript-eslint/eslint-recommended',
11
+ 'plugin:@typescript-eslint/recommended',
12
+ ],
13
+ parserOptions: {
14
+ project: './tsconfig-eslint.json'
15
+ },
16
+ rules: {
17
+ 'semi': 'off',
18
+ '@typescript-eslint/semi': ['error', 'always'],
19
+ '@typescript-eslint/no-empty-function': ['error', { 'allow': ['arrowFunctions'] }],
20
+ '@typescript-eslint/member-delimiter-style': ['error', { 'multiline': { 'delimiter': 'semi', 'requireLast': true }}],
21
+ '@typescript-eslint/interface-name-prefix': [0],
22
+ '@typescript-eslint/strict-boolean-expressions': [0],
23
+ '@typescript-eslint/no-explicit-any': [0], // remove one day, maybe. This is early days so we have some anys.
24
+ '@typescript-eslint/restrict-plus-operands': [0],
25
+ '@typescript-eslint/consistent-type-definitions': [0]
26
+ }
27
+ };
@@ -0,0 +1,4 @@
1
+ #!/bin/sh
2
+ . "$(dirname "$0")/_/husky.sh"
3
+
4
+ npx --no-install commitlint --edit $1
@@ -0,0 +1,4 @@
1
+ #!/bin/sh
2
+ . "$(dirname "$0")/_/husky.sh"
3
+
4
+ npm run lint
@@ -0,0 +1,5 @@
1
+ #!/bin/sh
2
+ . "$(dirname "$0")/_/husky.sh"
3
+
4
+ npm run lint
5
+ npm run test
package/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 Blockcerts
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,260 @@
1
+ # \<blockcerts-verifier\>
2
+
3
+ [![Build Status](https://travis-ci.com/blockchain-certificates/blockcerts-verifier.svg?branch=master)](https://travis-ci.com/blockchain-certificates/blockcerts-verifier)
4
+ [![codecov](https://codecov.io/gh/blockchain-certificates/blockcerts-verifier/branch/master/graph/badge.svg)](https://codecov.io/gh/blockchain-certificates/blockcerts-verifier)
5
+ [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
6
+
7
+ A standalone universal viewer &amp; verifier for blockcerts credentials
8
+
9
+ # Production
10
+ The component is developed with Polymer 3.
11
+ To use the component in your project, install it via:
12
+
13
+ ```
14
+ npm i @blockcerts/blockcerts-verifier
15
+ ```
16
+
17
+ If your project **does not require support for IE11**, you can use the following build:
18
+
19
+ ```html
20
+ <script src="node_modules/@blockcerts/blockcerts-verifier/dist/main.js"></script>
21
+
22
+ <blockcerts-verifier></blockcerts-verifier>
23
+ ```
24
+ Chrome will support natively the code, but for Firefox, Safari, MS Edge (Opera and Brave), you will need to add the webcomponent loader before:
25
+
26
+ ```html
27
+ <script src="node_modules/@webcomponents/webcomponentsjs/webcomponents-loader.js"></script>
28
+ ```
29
+
30
+ If your project **requires support for IE11**, you will need to use the ie11 build:
31
+ ```html
32
+ <script src="node_modules/@webcomponents/webcomponentsjs/custom-elements-es5-adapter.js"></script>
33
+ <script src="node_modules/@webcomponents/webcomponentsjs/webcomponents-loader.js"></script>
34
+ <script src="node_modules/@blockcerts/blockcerts-verifier/dist/ie11.js"></script>
35
+ ```
36
+ Please note that because this is transpiled to ES5, the custom-elements-es5-adapter code is required for it to work properly in more modern browsers.
37
+
38
+ Have a look at the [Demo Pages](/demo) to see examples of the usage
39
+
40
+ ## API Usage
41
+
42
+ ### Default behavior
43
+ By the default, the component will:
44
+ - Display a Blockcerts record in `card` mode (concise information)
45
+ - Will allow verification of a Blockcerts Record
46
+ - Enables auto-verification (verification as the record is loaded)
47
+
48
+ ### API
49
+ The component will understand the following options:
50
+
51
+ - `allow-download`: (Boolean. default: `false`). Enables the download of the record. At this moment only records provided by Learning Machine are downloadable.
52
+
53
+ Example:
54
+
55
+ ```html
56
+ <blockcerts-verifier allow-download></blockcerts-verifier>
57
+ ```
58
+ - `allow-social-share`: (Boolean. default: `false`). Allows sharing the record on the social networks (LinkedIn, Facebook and Twitter).
59
+
60
+ Example:
61
+
62
+ ```html
63
+ <blockcerts-verifier allow-social-share></blockcerts-verifier>
64
+ ```
65
+ - `disable-auto-verify`: (Boolean. default: `false`). Disables starting automatically the verification sequence as the record is loaded.
66
+
67
+ Example:
68
+
69
+ ```html
70
+ <blockcerts-verifier disable-auto-verify></blockcerts-verifier>
71
+ ```
72
+ - `disable-verify`: (Boolean. default: `false`). Disables verification of the record altogether.
73
+
74
+ Example:
75
+
76
+ ```html
77
+ <blockcerts-verifier disable-verify></blockcerts-verifier>
78
+ ```
79
+ - `display-mode`: (String, oneOf('card', 'full', 'fullscreen'). default: `card`).
80
+ Changes the display of a record.
81
+ - `card` will be a concise summary of the record with a link to the full record.
82
+ - `full` will show the actual record as designed by the emitter.
83
+ - `fullscreen` will display a two-column overlay (in desktop) that takes the window dimensions.
84
+ The certificate displays similar as `full`. NOTA: only works for certificates that have a `displayHTML` property.
85
+
86
+ Example:
87
+
88
+ ```html
89
+ <blockcerts-verifier display-mode="full"></blockcerts-verifier>
90
+ ```
91
+ - `show-metadata`: (Boolean. default: `false`). Enables showing the metadata of a record.
92
+
93
+ Example:
94
+
95
+ ```html
96
+ <blockcerts-verifier show-metadata></blockcerts-verifier>
97
+ ```
98
+ - `src`: (String. default: `''`). Allows loading an initial record with no further actions required. `src` can be either an absolute URL, or a relative path.
99
+
100
+ Example:
101
+
102
+ ```html
103
+ <blockcerts-verifier src='../fixtures/valid-certificate-example.json'></blockcerts-verifier>
104
+ ```
105
+ - `theme`: (String. default: `'bright'`). Adapts to the background of the page that hosts the component. If the component is displayed on a dark background, you should use the `dark` option. If it's bright, then use the `bright` option.
106
+
107
+ Example:
108
+
109
+ ```html
110
+ <blockcerts-verifier theme='dark'></blockcerts-verifier>
111
+ ```
112
+
113
+ - `locale`: (String. default: `'auto'`, if language code not recognized will default to English (`en`)). View `src/i18n/lang` to see the list of supported languages. Contributions welcome.
114
+
115
+ Example:
116
+
117
+ ```html
118
+ <blockcerts-verifier locale='fr'></blockcerts-verifier>
119
+ ```
120
+
121
+ - `clickable-urls`: (Boolean, default: `false`). When set to true, the certificate view will identify and convert to clickable links (`<a href=...) any url ([http(s)://(www.)]blockcerts.org/[params]) contained in the `displayHTML` property of the certificate.
122
+
123
+ ## Custom Blockchain explorers - `explorerAPIs`
124
+ Since v4.1.0 of [cert-verifier-js](https://github.com/blockchain-certificates/cert-verifier-js) accepts custom blockchain explorers, Blockcerts Verifier facilitates communicating such service for the verification process.
125
+
126
+ As the object would be quite complicated, the option cannot be passed as attribute, but rather via property, as follows:
127
+
128
+ ```javascript
129
+ const explorer = {
130
+ parsingFunction: function (): TransactionData {},
131
+ serviceURL: 'your-explorer-service.url',
132
+ priority: 0 | 1
133
+ }
134
+
135
+ document.addEventListener('DOMContentLoaded', function () {
136
+ const bv = document.querySelector('blockcerts-verifier');
137
+ bv.explorerAPIs = [explorer];
138
+ });
139
+ ```
140
+
141
+ See this section: https://github.com/blockchain-certificates/cert-verifier-js#explorerapis to get more information.
142
+
143
+ ## Event Tracking API
144
+ The component will emit events on different moment of the certificate life cycle.
145
+ To subscribe and track these events you should add on your consumer page event listeners on the `window` object.
146
+
147
+ See the [event demo page](https://github.com/blockchain-certificates/blockcerts-verifier/blob/master/demo/events.html) for a working example.
148
+
149
+ The information is communicated via the `detail` key of the event.
150
+
151
+ Supported Events:
152
+ - `certificate-load`
153
+
154
+ Triggered when a certificate has been loaded into the component.
155
+ Returns:
156
+ - the `certificateDefinition` (object) on which the action was called.
157
+
158
+ - `certificate-verify`
159
+
160
+ Triggered when the verification process of a certificate is started.
161
+ Returns:
162
+ - the `certificateDefinition` (object) on which the action was called.
163
+
164
+ - `certificate-share`
165
+
166
+ Triggered when a social network link is clicked.
167
+ Returns:
168
+ - the `certificateDefinition` (object) on which the action was called.
169
+ - the `socialNetwork` (string) to which the record was shared.
170
+
171
+
172
+
173
+ # Development
174
+ ## Viewing Your Element
175
+
176
+ ```
177
+ npm run start
178
+ ```
179
+
180
+ Will make the demo page available on http://localhost:8081/demo/.
181
+
182
+ ## Modifying the Sanitizer
183
+
184
+ The `sanitizer` is used in order to protect against malicious certificates that could hold XSS attacks.
185
+ It is an overlay of the [xss](https://www.npmjs.com/package/xss) library, since at times, you might want to be able to configure or adapt the whitelist to your own needs.
186
+
187
+ To modify it, you should edit the `sanitizer/index.js` file.
188
+
189
+ #### Whitelist CSS properties
190
+ More specifically if you wish to whitelist some CSS properties, add them to the object `whiteListedCssProperties`.
191
+
192
+ #### Generate the updated sanitizer
193
+ ```
194
+ npm run build:sanitizer
195
+ ```
196
+
197
+ This will generate the `sanitizer.js` file, which is then used by the application and the tests.
198
+
199
+ If you want to work on the sanitizer in watch mode (and auto-generate your changes), use the following command:
200
+
201
+ ```
202
+ npm run build:sanitizer -- -w
203
+ ```
204
+
205
+ ## Running Tests
206
+
207
+ ### Application Tests
208
+
209
+ ```
210
+ npm run test:application
211
+ ```
212
+
213
+ NOTE: application must be started to run the tests, or at the very least the mock-server via the `npm run start:mock-server` (automatically included in the `npm run start` command).
214
+
215
+ **watch mode**
216
+
217
+ ```
218
+ npm run test:application:watch
219
+ ```
220
+
221
+ ### Component Tests
222
+ ```
223
+ npm run test:components
224
+ ```
225
+
226
+ **"watch" mode**
227
+ ```
228
+ npm run test:components:persist
229
+ ```
230
+ Will allow refreshing the test page: http://localhost:8000/components/blockcerts-verifier/generated-index.html?cli_browser_id=0
231
+
232
+ ## Dealing with CSS
233
+ The `npm run start` command will also start a SASS compiler watcher, which means that any stylesheet within the `components` folder will be transpiled to a polymer component that can be reused within another component. ie:
234
+
235
+ ```javascript
236
+ import CSS from './_components.button-css';
237
+ [...]
238
+ _render () {
239
+ return html`${CSS}[...]`
240
+ }
241
+ ```
242
+
243
+ ### Using shared styles
244
+ To reduce the amount of code duplication, and following the ITCSS philosophy, you may need to import some of the shared-styles in your component.
245
+ To do so, in your component's SASS file, add the following instruction:
246
+
247
+ ```javascript
248
+ /* in _components.my-component.sass */
249
+
250
+ @import '../../../shared-styles/objects.text';
251
+
252
+ [...component styles]
253
+
254
+ @import '../../../shared-styles/utils.a11y';
255
+ ```
256
+
257
+ Please note that the SASS watcher does not observe changes in the shared styles folder, and will not automatically recompile any consumer stylesheet. You will have to recompile them yourselves (TODO: improve DevX here).
258
+
259
+ ## More info
260
+ Please have a look through the [ADR](/docs/ADR) documentation to get more context around the architecture and the ways of developing a component.
@@ -0,0 +1,10 @@
1
+ import { html } from '@polymer/lit-element';
2
+
3
+ class LitElement {
4
+ _propertiesChanged () {}
5
+ }
6
+
7
+ export {
8
+ LitElement,
9
+ html
10
+ };
@@ -0,0 +1,35 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, minimum-scale=1, initial-scale=1, user-scalable=yes">
6
+
7
+ <title>blockcerts-verifier demo</title>
8
+
9
+ <script src="./@webcomponents/webcomponentsjs/webcomponents-loader.js"></script>
10
+ <script type="module" src="./index.js"></script>
11
+
12
+ <script>
13
+ // HACK(keanulee): The Redux package assumes `process` exists - mock it here before
14
+ // the module is loaded.
15
+ window.process = {
16
+ env: {
17
+ NODE_ENV: 'development'
18
+ }
19
+ };
20
+ </script>
21
+ <style>
22
+ .main {
23
+ max-width: 700px;
24
+ margin: 0 auto;
25
+ width: 100%;
26
+ }
27
+ </style>
28
+ </head>
29
+ <body>
30
+ <div class="main">
31
+ <h3>Basic blockcerts-verifier demo - Allow Download flag</h3>
32
+ <blockcerts-verifier display-mode="full" allow-download></blockcerts-verifier>
33
+ </div>
34
+ </body>
35
+ </html>
@@ -0,0 +1,35 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, minimum-scale=1, initial-scale=1, user-scalable=yes">
6
+
7
+ <title>blockcerts-verifier demo</title>
8
+
9
+ <script src="./@webcomponents/webcomponentsjs/webcomponents-loader.js"></script>
10
+ <script type="module" src="./index.js"></script>
11
+
12
+ <script>
13
+ // HACK(keanulee): The Redux package assumes `process` exists - mock it here before
14
+ // the module is loaded.
15
+ window.process = {
16
+ env: {
17
+ NODE_ENV: 'development'
18
+ }
19
+ };
20
+ </script>
21
+ <style>
22
+ .main {
23
+ max-width: 700px;
24
+ margin: 0 auto;
25
+ width: 100%;
26
+ }
27
+ </style>
28
+ </head>
29
+ <body>
30
+ <div class="main">
31
+ <h3>Basic blockcerts-verifier demo - Allow Social Share flag</h3>
32
+ <blockcerts-verifier display-mode="full" allow-social-share></blockcerts-verifier>
33
+ </div>
34
+ </body>
35
+ </html>
@@ -0,0 +1,40 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, minimum-scale=1, initial-scale=1, user-scalable=yes">
6
+
7
+ <title>blockcerts-verifier demo</title>
8
+
9
+ <script src="./@webcomponents/webcomponentsjs/webcomponents-loader.js"></script>
10
+ <script type="module" src="./index.js"></script>
11
+
12
+ <script>
13
+ // HACK(keanulee): The Redux package assumes `process` exists - mock it here before
14
+ // the module is loaded.
15
+ window.process = {
16
+ env: {
17
+ NODE_ENV: 'development'
18
+ }
19
+ };
20
+ </script>
21
+ <style>
22
+ .main {
23
+ max-width: 700px;
24
+ margin: 0 auto;
25
+ width: 100%;
26
+ }
27
+ .wrapper {
28
+ background-color: #85c8e0
29
+ }
30
+ </style>
31
+ </head>
32
+ <body>
33
+ <div class="main">
34
+ <h3>Basic blockcerts-verifier demo - Bright Theme (default)</h3>
35
+ <div class="wrapper">
36
+ <blockcerts-verifier theme="bright"></blockcerts-verifier>
37
+ </div>
38
+ </div>
39
+ </body>
40
+ </html>