Skip to content

Commit

Permalink
chore: update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Nebulis committed Dec 26, 2019
1 parent badaa65 commit 47a7c25
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 29 deletions.
130 changes: 106 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![CircleCI](https://circleci.com/gh/Open-Attestation/oa-verify.svg?style=svg)](https://circleci.com/gh/Open-Attestation/oa-verify)

Library to verify any [OpenAttestation](https://github.com/OpenCerts/open-attestation) document.
Library to verify any [OpenAttestation](https://github.com/OpenCerts/open-attestation) document. This library implements [the verifier ADR](https://github.com/Open-Attestation/adr/blob/master/verifier.md).

## Installation

Expand All @@ -12,38 +12,120 @@ npm install @govtechsg/oa-verify

## Usage

```js
const document = require("./document.json");
const verify = require("@govtechsg/oa-verify");
```typescript
import { documentRopstenValidWithToken } from "./test/fixtures/v2/documentRopstenValidWithToken";
import { verify, isValid } from "@govtechsg/oa-verify";

verify(document).then(console.log);
verify(documentRopstenValidWithToken).then(console.log); // see below
console.log(isValid(results)); // display true
```

```json
{
"hash": {
"checksumMatch": true
[
{
"data": true,
"status": "VALID",
"name": "OpenAttestationHash",
"type": "DOCUMENT_INTEGRITY"
},
"issued": {
"issuedOnAll": true,
"details": [
{
"address": "0x48399Fb88bcD031C556F53e93F690EEC07963Af3",
"issued": true
}
]
{
"message": "Document issuers doesn't have \"documentStore\" or \"certificateStore\" property or DOCUMENT_STORE method",
"name": "OpenAttestationEthereumDocumentStoreIssued",
"status": "SKIPPED",
"type": "DOCUMENT_STATUS"
},
{
"data": {
"details": [
{
"address": "0xe59877ac86c0310e9ddaeb627f42fdee5f793fbe",
"minted": true
}
],
"mintedOnAll": true
},
"status": "VALID",
"name": "OpenAttestationEthereumTokenRegistryMinted",
"type": "DOCUMENT_STATUS"
},
"revoked": {
"revokedOnAny": false,
"details": [
{
"message": "Document issuers doesn't have \"documentStore\" or \"certificateStore\" property or DOCUMENT_STORE method",
"name": "OpenAttestationEthereumDocumentStoreRevoked",
"status": "SKIPPED",
"type": "DOCUMENT_STATUS"
},
{
"data": [
{
"address": "0x48399Fb88bcD031C556F53e93F690EEC07963Af3",
"revoked": false
"dns": "example.tradetrust.io",
"identified": true,
"smartContract": "0xe59877ac86c0310e9ddaeb627f42fdee5f793fbe"
}
]
],
"status": "VALID",
"name": "OpenAttestationDnsTxt",
"type": "ISSUER_IDENTITY"
}
]
```

## Advanced usage

### Verify

By default the provided `verify` method performs multiple checks on a document

- for the type `DOCUMENT_STATUS`: it runs `OpenAttestationEthereumDocumentStoreIssued`, `OpenAttestationEthereumDocumentStoreRevoked` and `OpenAttestationEthereumTokenRegistryIssued` verifiers
- for the type `DOCUMENT_INTEGRITY`: it runs `OpenAttestationHash` verifier
- for the type `ISSUER_IDENTITY`: it runs `OpenAttestationDnsTxt` verifier

All those verifiers are exported as `openAttestationVerifiers`

You can build your own verify method or you own verifiers:

```typescript
import { verificationBuilder, openAttestationVerifiers } from "@govtechsg/oa-verify";

// creating your own verify using default exported verifiers
const verify = verificationBuilder(openAttestationVerifiers); // this verify is equivalent to the one exported by the library
const verify = verificationBuilder([openAttestationVerifiers[0], openAttestationVerifiers[1]]); // this verify only run 2 verifiers

// creating your own verify using custom verifier
import { verificationBuilder, openAttestationVerifiers, Verifier } from "@govtechsg/oa-verify";
const customVerifier: Verifier = {
skip: () => {
// return a SkippedVerificationFragment if the verifier should be skipped or throw an error if it should always run
},
test: () => {
// return true or false
},
"valid": true
}
verify: async document => {
// perform checks and returns a fragment
}
};

// create your own verify function with all verifiers and your custom one
const verify = verificationBuilder([...openAttestationVerifiers, customVerifier]);
```

### isValid

By default, `isValid` perform checks on every types that exists for a fragment:

- `DOCUMENT_STATUS`
- `DOCUMENT_INTEGRITY`
- `ISSUER_IDENTITY`
it ensures that for every types, there is at least one `VALID` fragment and no `INVALID` or `ERROR` fragment.

The function allow to specify as a second parameters the list of types on which to perform the checks

```typescript
import { documentRopstenValidWithCertificateStore } from "./test/fixtures/v2/documentRopstenValidWithCertificateStore";
import { verify, isValid } from "@govtechsg/oa-verify";

const fragments = verify(documentRopstenValidWithCertificateStore);
isValid(fragments); // display false because ISSUER_IDENTITY is INVALID
isValid(fragments, ["DOCUMENT_INTEGRITY", "DOCUMENT_STATUS"]); // display true because those types are VALID
```

## License
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ const openAttestationVerifiers: Verifier<

const verify = verificationBuilder(openAttestationVerifiers);

export { verificationBuilder, openAttestationVerifiers, isValid, verify };
export { verificationBuilder, openAttestationVerifiers, isValid, verify, Verifier };
6 changes: 2 additions & 4 deletions src/verifiers/openAttestationHash.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { v2, v3, verifySignature, WrappedDocument } from "@govtechsg/open-attestation";
import { verifySignature } from "@govtechsg/open-attestation";
import { VerificationFragmentType, Verifier } from "../types/core";

const name = "OpenAttestationHash";
const type: VerificationFragmentType = "DOCUMENT_INTEGRITY";
export const openAttestationHash: Verifier<
WrappedDocument<v2.OpenAttestationDocument> | WrappedDocument<v3.OpenAttestationDocument>
> = {
export const openAttestationHash: Verifier = {
skip: () => {
throw new Error("This verifier is never skipped");
},
Expand Down

0 comments on commit 47a7c25

Please sign in to comment.