Code Monkey home page Code Monkey logo

blockcerts-verifier's Introduction

<blockcerts-verifier>

Build Status codecov semantic-release

A standalone universal viewer & verifier for blockcerts credentials

Production

The component is developed with Polymer 3. To use the component in your project, install it via:

  npm i @blockcerts/blockcerts-verifier
  <script type="module" src="node_modules/@blockcerts/blockcerts-verifier/dist/main.js"></script>

  <blockcerts-verifier></blockcerts-verifier>

Chrome will support natively the code, but for Firefox, Safari, MS Edge (Opera and Brave), you will need to add the webcomponent loader before:

    <script src="node_modules/@webcomponents/webcomponentsjs/webcomponents-loader.js"></script>

Have a look at the Demo Pages to see examples of the usage

API Usage

Default behavior

By the default, the component will:

  • Display a Blockcerts record in card mode (concise information)
  • Will allow verification of a Blockcerts Record
  • Enables auto-verification (verification as the record is loaded)

API

The component will understand the following options:

  • allow-download: (Boolean. default: false). Enables the download of the record. At this moment only records provided by Learning Machine are downloadable.

    Example:

    <blockcerts-verifier allow-download></blockcerts-verifier>
  • allow-social-share: (Boolean. default: false). Allows sharing the record on the social networks (LinkedIn, Facebook and Twitter).

    Example:

    <blockcerts-verifier allow-social-share></blockcerts-verifier>
  • disable-auto-verify: (Boolean. default: false). Disables starting automatically the verification sequence as the record is loaded.

    Example:

    <blockcerts-verifier disable-auto-verify></blockcerts-verifier>
  • disable-download-pdf: (Boolean. default: false). Disables the Download PDF functionality.

    Example:

    <blockcerts-verifier disable-download-pdf></blockcerts-verifier>
  • disable-verify: (Boolean. default: false). Disables verification of the record altogether.

    Example:

    <blockcerts-verifier disable-verify></blockcerts-verifier>
  • display-mode: (String, oneOf('card', 'full', 'fullscreen'). default: card). Changes the display of a record.

    • card will be a concise summary of the record with a link to the full record.
    • full will show the actual record as designed by the emitter.
    • fullscreen will display a two-column overlay (in desktop) that takes the window dimensions. The certificate displays similar as full. NOTA: only works for certificates that have a displayHTML property.

    Example:

    <blockcerts-verifier display-mode="full"></blockcerts-verifier>
  • show-metadata: (Boolean. default: false). Enables showing the metadata of a record.

    Example:

    <blockcerts-verifier show-metadata></blockcerts-verifier>
  • src: (String. default: ''). Allows loading an initial record with no further actions required. src can be either an absolute URL, a relative path or a stringified certificate definition.

    Example:

    <blockcerts-verifier src='../fixtures/valid-certificate-example.json'></blockcerts-verifier>
  • 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.

    Example:

    <blockcerts-verifier theme='dark'></blockcerts-verifier>
  • 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.

    Example:

    <blockcerts-verifier locale='fr'></blockcerts-verifier>
  • 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.

Custom Blockchain explorers - explorerAPIs

Since v4.1.0 of cert-verifier-js accepts custom blockchain explorers, Blockcerts Verifier facilitates communicating such service for the verification process.

As the object would be quite complicated, the option cannot be passed as attribute, but rather via property, as follows:

const explorer = {
  parsingFunction: function (): TransactionData {},
  serviceURL: 'your-explorer-service.url',
  priority: 0 | 1
}
    
document.addEventListener('DOMContentLoaded', function () {
  const bv = document.querySelector('blockcerts-verifier');
  bv.explorerAPIs = [explorer];
});

See this section: https://github.com/blockchain-certificates/cert-verifier-js#explorerapis to get more information.

Event Tracking API

The component will emit events on different moment of the certificate life cycle. To subscribe and track these events you should add on your consumer page event listeners on the window object.

See the event demo page for a working example.

The information is communicated via the detail key of the event.

Supported Events:

  • certificate-load

    Triggered when a certificate has been loaded into the component. Returns:

    • the certificateDefinition (object) on which the action was called.
  • certificate-verify

    Triggered when the verification process of a certificate is started. Returns:

    • the certificateDefinition (object) on which the action was called.
  • certificate-share

    Triggered when a social network link is clicked. Returns:

    • the certificateDefinition (object) on which the action was called.
    • the socialNetwork (string) to which the record was shared.

Development

Viewing Your Element

npm run start

Will make the demo page available on http://localhost:8081/demo/.

Modifying the Sanitizer

The sanitizer is used in order to protect against malicious certificates that could hold XSS attacks. It is an overlay of the xss library, since at times, you might want to be able to configure or adapt the whitelist to your own needs.

To modify it, you should edit the sanitizer/index.js file.

Whitelist CSS properties

More specifically if you wish to whitelist some CSS properties, add them to the object whiteListedCssProperties.

Generate the updated sanitizer

  npm run build:sanitizer

This will generate the sanitizer.js file, which is then used by the application and the tests.

If you want to work on the sanitizer in watch mode (and auto-generate your changes), use the following command:

  npm run build:sanitizer -- -w

Running Tests

Application Tests

npm run test:application

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).

watch mode

npm run test:application:watch

Component Tests

npm run test:components

"watch" mode

npm run test:components:persist

Will allow refreshing the test page: http://localhost:8000/components/blockcerts-verifier/generated-index.html?cli_browser_id=0

Dealing with CSS

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:

import CSS from './_components.button-css';
[...]
_render () {
    return html`${CSS}[...]`
}

Using shared styles

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. To do so, in your component's SASS file, add the following instruction:

/* in _components.my-component.sass */

@import '../../../shared-styles/objects.text';

[...component styles]

@import '../../../shared-styles/utils.a11y';

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).

More info

Please have a look through the ADR documentation to get more context around the architecture and the ways of developing a component.

blockcerts-verifier's People

Contributors

amazanzan avatar dariomas avatar davidlj95 avatar dependabot-preview[bot] avatar dependabot-support avatar dependabot[bot] avatar lemoustachiste avatar raiseandfall avatar shoito avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

blockcerts-verifier's Issues

Issue in running locally

npm run start

It's showing the error of "The system cannot find the file :mock-server".

HP@LAPTOP-K2A8KOQA MINGW64 ~/Desktop/blockcerts-verifier (master)
$ npm run start

> @blockcerts/[email protected] start C:\Users\HP\Desktop\blockcerts-verifier
> concurrently 'rollup -c rollup.dev.config.js -w' 'npm run styles:compile:watch' 'npm run start:mock-server'

[2] The filename, directory name, or volume label syntax is incorrect.
[0] ''rollup' is not recognized as an internal or external command,
[0] operable program or batch file.
[2] styles:compile:watch' exited with code 1
[0] 'rollup exited with code 1
[1] 'run' is not recognized as an internal or external command,
[1] operable program or batch file.
[3] ''npm' is not recognized as an internal or external command,
[3] operable program or batch file.
[4] 'run' is not recognized as an internal or external command,
[4] operable program or batch file.
[1] run exited with code 1
[4] run exited with code 1
[3] 'npm exited with code 1
[5] The system cannot find the file :mock-server'.
[5] start:mock-server' exited with code 1
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @blockcerts/[email protected] start: `concurrently 'rollup -c rollup.dev.config.js -w' 'npm run styles:compile:watch' 'npm run start:mock-server'`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the @blockcerts/[email protected] start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\HP\AppData\Roaming\npm-cache\_logs\2020-10-09T10_26_07_222Z-debug.log

So, please can anyone help how should I remove this error.

Steps I have followed:-

  1. Clone the repository
  2. Install the dependencies through

npm install

  1. npm run start

viewer rendering update

I submitted this pull request:

#143

Build on travis fails due (I guess) to something not related to my changes.
Can you help me?
Thank you

The automated release is failing 🚨

🚨 The automated release from the master branch failed. 🚨

I recommend you give this issue a high priority, so other packages depending on you could benefit from your bug fixes and new features.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can resolve this 💪.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the master branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here is some links that can help you:

If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


Invalid npm token.

The npm token configured in the NPM_TOKEN environment variable must be a valid token allowing to publish to the registry https://registry.npmjs.org/.

If you are using Two-Factor Authentication, make configure the auth-only level is supported. semantic-release cannot publish with the default auth-and-writes level.

Please make sure to set the NPM_TOKEN environment variable in your CI with the exact value of the npm token.


Good luck with your project ✨

Your semantic-release bot 📦🚀

Unable to run locally [ need help ]

$ npm run start

( its showing this error )

Error: Failed to replace env in config: ${NPM_TOKEN}
    at /usr/share/npm/lib/config/core.js:415:13
    at String.replace (<anonymous>)
    at envReplace (/usr/share/npm/lib/config/core.js:411:12)
    at parseField (/usr/share/npm/lib/config/core.js:389:7)
    at /usr/share/npm/lib/config/core.js:330:24
    at Array.forEach (<anonymous>)
    at Conf.add (/usr/share/npm/lib/config/core.js:328:23)
    at ConfigChain.addString (/usr/share/nodejs/config-chain/index.js:244:8)
    at Conf.<anonymous> (/usr/share/npm/lib/config/core.js:316:10)
    at /usr/share/nodejs/graceful-fs/graceful-fs.js:115:16
/usr/share/npm/lib/npm.js:59
      throw new Error('npm.load() required')
      ^

Error: npm.load() required
    at Object.get (/usr/share/npm/lib/npm.js:59:13)
    at process.errorHandler (/usr/share/npm/lib/utils/error-handler.js:205:32)
    at process.emit (events.js:198:13)
    at process._fatalException (internal/bootstrap/node.js:497:27)

JSON-LD Normalization Failed

Hello,

I'm having issues with my application on my remote server (works on my local vm, thoe), specifically when verifying. The verifier won't get pass the Computing local hash step. Not sure, what to share since I'm clueless of where the issue is coming from, but I can provide if necesary. The only thing I'm doing different is that I'm serving the module files from express and not using the plain <script type="module" src="node_modules/@blockcerts/blockcerts-verifier/dist/main.js"></script> tag, I would highly appreciate your help :)

(also I apoligize if this is not the right place for these kind of support)

Issuer's public key displayed is not being verified

We realized in the last version of the blockcerts-verifier, a field appears displaying the issuer's public key, concretely in the buv-certificate-details atom component, that takes the information from a selector:

https://github.com/blockchain-certificates/blockcerts-verifier/blob/master/src/selectors/certificate.js#L228

The issue here is that this public key is the supposed to be the one used for assertion registration in the blockchain, but no code checks that. Therefore it could be possible that the verification.publicKey field does not match the key used for the blockchain registration of the assertion and the identity of the issuer could be faked.

I don't know if that's a task the cert-verifier-js should do btw.

I also wrote a post about issuer identification in Blockcerts in the forum:
https://community.blockcerts.org/t/dids-as-a-way-to-properly-identify-issuers/2085

Remove the drag and drop message when on mobile

On mobile drag and drop is not possible.
While removing completely the drag and drop behavior might prove complicated, we should remove the message that encourages drag and drop when using the component on mobile devices.

Expected public key to be an Uint8Array with length [33, 65]

Hi guys,

I am trying to validate a valid json Blockcerts credential V2 and Im getting the following error in the Identity verification step:

Expected public key to be an Uint8Array with length [33, 65]

screenshot1

Here is my valid json:

{
	"@context": ["https://www.w3.org/2018/credentials/v1", "https://w3id.org/blockcerts/v3"],
	"id": "urn:uuid:bbba8553-8ec1-445f-82c9-a57251dd731c",
	"type": ["VerifiableCredential", "BlockcertsCredential"],
	"issuer": "did:web:d17ab87jdkvb30.cloudfront.net",
	"issuanceDate": "2023-05-18T00:00:00Z",
	"credentialSubject": {"id": "did:example:ebfeb1f712ebc6f1c276e12ec21", "name": "LAI"},
	"proof": {
		"type": "MerkleProof2019",
		"created": "2023-05-18T07:38:21.617957",
		"proofValue": "znKD4YGVqA8texttcfpkbF2mPUYAguT8rCYUw4i2ocLkDtYC326bidW8hFzjneDy2TLgD5gu4fpeBsZH4hgDqvkpKT7SQSuXpLWipJ3Kia7Y8T3c8mDcs11Y6Ay5FYLrDXGANx11u22LRwckBxUxuatR3GqVJ795eTcPZDzg9YJdLxzA6ydMJdnY2PzSfHg61U3ksvNo9cvTKWbJM34i8cSvQzgiAkmQagNcNzHRPBNU29tHckJs5K4nAit6EzCAAQyRUD73PgJw76ipFRvkziaWLrNeZT8av5aSUCKrEZLNXkyYMwKZ5trCtns",
		"proofPurpose": "assertionMethod",
		"verificationMethod": "did:web:d17ab87jdkvb30.cloudfront.net#key-1"
	}
}

I can not get reason that why this error message happened.

It will save me day if somebody know that how to fix it.

Thanks

Deprecate IE11 build

v6.0.0 has a failing ie11.js distribution build.

We do not intend to fix this and will actually remove the build from future versions.

Consumers should now use the main.js build.

TypeError when loading remote contexts

Issue

We are using external JSON-LD context.jsons in our certificates that add some data not included in Blockcerts context.jsons.

Symptoms

A TypeError is triggered when using another remote context rather than the default, cached ones (Open Badges v2, Blockcerts v2, embedded context)

Stacktrace

TypeError: i is not a function

      at i (node_modules/@blockcerts/cert-verifier-js/dist/verifier-es.js:1:268153)
      at e.RequestQueue.u [as _loader] (node_modules/@blockcerts/cert-verifier-js/dist/verifier-es.js:1:267523)
      at e.RequestQueue._loader [as add] (node_modules/@blockcerts/cert-verifier-js/dist/verifier-es.js:1:264385)
      at Function.i [as documentLoader] (node_modules/@blockcerts/cert-verifier-js/dist/verifier-es.js:1:330140)
      at documentLoader (node_modules/@blockcerts/cert-verifier-js/dist/verifier-es.js:1:260137)
      at r (node_modules/@blockcerts/cert-verifier-js/dist/verifier-es.js:1:313671)
      at o (node_modules/@blockcerts/cert-verifier-js/dist/verifier-es.js:1:312546)
      at o (node_modules/@blockcerts/cert-verifier-js/dist/verifier-es.js:1:313729)
      at i (node_modules/@blockcerts/cert-verifier-js/dist/verifier-es.js:1:249477)
      at i (node_modules/@blockcerts/cert-verifier-js/dist/verifier-es.js:1:250035)
      at Item.apply [as run] (node_modules/@blockcerts/cert-verifier-js/dist/verifier-es.js:1:158962)
      at run (node_modules/@blockcerts/cert-verifier-js/dist/verifier-es.js:1:158578)
      at Timeout.callback [as _onTimeout] (node_modules/jsdom/lib/jsdom/browser/Window.js:628:19)

Reproduce the issue

Change test/fixtures/valid-certificate-example.json Blockcerts context and use the v2.1 one:

-    "https://w3id.org/blockcerts/v2",
+    "https://w3id.org/blockcerts/v2.1",

Run the mock server with npm start:mock-server and run tests with npm run test

Causes

Loading a remote context makes jsonld dependency fail when executing the function loadDocument in documentLoaders/xhr.js

Suggestions

Upgrade jsonld dependency in cert-verifier-js. Haven't tried but maybe could work.

What we tried

Testing to verifiy a certificate with a remote context certificate in cert-verifier-js doesn't cause any problems.

Thanks in advance if you can provide any help!

cache-control is not allowed by Access-Control-Allow-Headers in preflight response

Hi guys,

I am trying to validate a valid json Blockcerts credential V2 and Im getting the following error:

Access to XMLHttpRequest at 'https://api.etherscan.io/api?module=proxy&action=eth_getTransactionByHash&txhash=0x21a53b030da894ce42b1f18483bc59ef4c3e8f9d2b5b36b3769954487fe73b2b&apikey=XXXXXXXXXXXXXX' from origin 'https://www.blockcerts.org/' has been blocked by CORS policy: Request header field cache-control is not allowed by Access-Control-Allow-Headers in preflight response.

After a long time dealing with it... I found that the problem🐞🐞🐞 was the following code:

.setRequestHeader("Cache-Control","no-cache, no-store, max-age=0")

Please remove this part from the code in order to make it work again.

shared-styles access through node package

I've been trying to workout how to implement my own shared-styles. The src folder is ignored by npm so there is no way to access any of those files of add any of my own. Can someone provide an example of how I can make use of share-styles to add css before the credential display html due to the fact that the sanitizer takes out anything associated with styling.

Verifiable Credentials update

I wanted to utilize this library for verifying verifiable credentials. Has this been implementing already? I created a couple certificates using the alpha versions in cert-tools and cert-issuer, but I receive the message that it's not a valid credential.

Correct method for debugging

I have some failures when verifying the certificates that I issue. I think the problems stem from misconfiguration in cert-issuer. But to help me find the problem I would like to be able to debug this component. Could you help me debug this project? What tools do you use and what configuration files? Thank you

Adding new dependencies

I'm new to polymer and rollup.js and i'm trying to add a new dependency to the project by using the below command
npm install ipfs-http-client
This command installs the dependency and update the package.json

When I try to import that specific module
import {create} from 'ipfs-http-client' i'm facing a error

[!] Error: 'create' is not exported by node_modules/ipfs-http-client/index.js, imported by src/components/atoms/FileUpload/FileUpload.js [0] https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module [0] src/components/atoms/FileUpload/FileUpload.js (12:8) [0] 10: // ipfsScript.setAttribute('src','https://cdn.jsdelivr.net/npm/ipfs-http-client/dist/index.min.js'); [0] 11: // document.head.appendChild(ipfsScript); [0] 12: import {create} from 'ipfs-http-client'; [0] ^
I this is the issue with rollup
How can i solve this?

Allow PR's to build in travis

PR from outside contributors typically fail because they are missing an NPM_TOKEN, which we have in our travis configs but secret variables are not pulled in for PR's. See: https://docs.travis-ci.com/user/pull-requests/#pull-requests-and-security-restrictions

Travis also recommends skipping certain tests that rely on secret variables.

Are there any ways we can get around this problem? I see one suggestion https://docs.npmjs.com/using-private-packages-in-a-ci-cd-workflow

Valid V3-alpha Blockcerts show as invalid on mobile browsers on first load only

Environment:

I have confirmed this bug using Chrome and Safari on iOS on blockcerts.org as well as my own deployment ([email protected])

Method to reproduce:

Just load a valid V3-alpha Ethereum Blockcert by URL on iOS Chrome or Safari. (another mobile browser may work too. Not sure whether this bug occurs with Bitcoin Blockcerts.)
The certificate will not validate, displaying Invalid Merkle Receipt. Proof hash did not match Merkle root
However, if you clear the credential with the "X" icon and enter the same URL again, it will show as valid.

Proposal:

I'm not sure of the cause, but since blockcerts-verifier is clearly capable of validating the credential properly even on mobile, I would guess there's just a quick fix to be made in the verification sequence for V3 credentials on mobile.

Thoughts?

Verification on testnet indistinguable from mainnet

Hi,

I see that using a certificate json signed on testnet (Ropsten, for example) the result is the same like when using a certifcate signed on the mainnet.

I think that there should be some clear note on the verification prompt to warn the user that the certificate has been only signed on the test-net.

Customize download JSON link

Hello guys!

Do blockcerts-verifier have an opportunity to customize link for downloading?
I will be appreciative for this feature in close future🙏

Download blockcerts

Hi,
I read "allow-download: (Boolean. default: false). Enables the download of the record. At this moment only records provided by Learning Machine are downloadable.".

What's the reason? I'd like to use it with all certificates in blockchain.

Thank you.

Improve test reliability

Tests are often unreliable, as they will fail over network issues.

This is because some tests are bound to the actual behaviour of cert-verifier-js which performs live checks over the network.

It'd be good to improve the reliability and confidence in the tests, by switching to contract testing.
Using Pact, we can add consumer's tests within blockcerts-verifier and provider's tests to cert-verifier-js.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.