Skip to content

Commit

Permalink
feat: combined document store issue & revoke to status
Browse files Browse the repository at this point in the history
Co-authored-by: Raymond Yeh <[email protected]>
  • Loading branch information
yehjxraymond and yehjxraymond authored Aug 13, 2020
1 parent 55fd1c7 commit 714b0ef
Show file tree
Hide file tree
Showing 22 changed files with 1,682 additions and 2,235 deletions.
59 changes: 34 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,63 +24,72 @@ console.log(isValid(fragments)); // display true
```json
[
{
"data": true,
"status": "VALID",
"type": "DOCUMENT_INTEGRITY",
"name": "OpenAttestationHash",
"type": "DOCUMENT_INTEGRITY"
"data": true,
"status": "VALID"
},
{
"message": "Document issuers doesn't have \"documentStore\" or \"certificateStore\" property or DOCUMENT_STORE method",
"name": "OpenAttestationEthereumDocumentStoreIssued",
"status": "SKIPPED",
"type": "DOCUMENT_STATUS"
"type": "DOCUMENT_STATUS",
"name": "OpenAttestationSignedProof",
"reason": {
"code": 4,
"codeString": "SKIPPED",
"message": "Document does not have a proof block"
}
},
{
"name": "OpenAttestationEthereumTokenRegistryStatus",
"type": "DOCUMENT_STATUS",
"data": {
"mintedOnAll": true,
"details": [
{
"address": "0xe59877ac86c0310e9ddaeb627f42fdee5f793fbe",
"minted": true
"minted": true,
"address": "0xe59877ac86c0310e9ddaeb627f42fdee5f793fbe"
}
],
"mintedOnAll": true
]
},
"status": "VALID",
"name": "OpenAttestationEthereumTokenRegistryMinted",
"type": "DOCUMENT_STATUS"
"status": "VALID"
},
{
"message": "Document issuers doesn't have \"documentStore\" or \"certificateStore\" property or DOCUMENT_STORE method",
"name": "OpenAttestationEthereumDocumentStoreRevoked",
"status": "SKIPPED",
"type": "DOCUMENT_STATUS"
"type": "DOCUMENT_STATUS",
"name": "OpenAttestationEthereumDocumentStoreStatus",
"reason": {
"code": 4,
"codeString": "SKIPPED",
"message": "Document issuers doesn't have \"documentStore\" or \"certificateStore\" property or DOCUMENT_STORE method"
}
},
{
"name": "OpenAttestationDnsTxt",
"type": "ISSUER_IDENTITY",
"data": [
{
"dns": "example.tradetrust.io",
"identified": true,
"smartContract": "0xe59877ac86c0310e9ddaeb627f42fdee5f793fbe"
"status": "VALID",
"location": "example.tradetrust.io",
"value": "0xe59877ac86c0310e9ddaeb627f42fdee5f793fbe"
}
],
"status": "VALID",
"name": "OpenAttestationDnsTxt",
"type": "ISSUER_IDENTITY"
"status": "VALID"
}
]
```

## Advanced usage

### Environment Variables

- `ETHEREUM_PROVIDER`: let you pick the provider you want to use. Available values: `cloudflare`. The provider will default to `infura` if the variable is not set.
- `INFURA_API_KEY`: let you provide your own `INFURA` API key.

### 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_STATUS`: it runs `OpenAttestationEthereumDocumentStoreStatus` and `OpenAttestationEthereumTokenRegistryStatus` verifiers
- for the type `DOCUMENT_INTEGRITY`: it runs `OpenAttestationHash` verifier
- for the type `ISSUER_IDENTITY`: it runs `OpenAttestationDnsTxt` verifier

Expand All @@ -104,9 +113,9 @@ const customVerifier: Verifier = {
test: () => {
// return true or false
},
verify: async document => {
verify: async (document) => {
// perform checks and returns a fragment
}
},
};

// create your own verify function with all verifiers and your custom one
Expand Down
38 changes: 16 additions & 22 deletions src/common/smartContract/documentStoreErrors.ts
Original file line number Diff line number Diff line change
@@ -1,47 +1,41 @@
import { errors } from "ethers";
import {
EthersError,
Hash,
OpenAttestationEthereumDocumentStoreIssuedCode,
OpenAttestationEthereumDocumentStoreRevokedCode,
Reason,
} from "../..";
import { EthersError, Hash, OpenAttestationEthereumDocumentStoreStatusCode, Reason } from "../..";

const contractNotFound = (address: Hash): Reason => {
return {
code: OpenAttestationEthereumDocumentStoreIssuedCode.CONTRACT_NOT_FOUND,
code: OpenAttestationEthereumDocumentStoreStatusCode.CONTRACT_NOT_FOUND,
codeString:
OpenAttestationEthereumDocumentStoreIssuedCode[OpenAttestationEthereumDocumentStoreIssuedCode.CONTRACT_NOT_FOUND],
OpenAttestationEthereumDocumentStoreStatusCode[OpenAttestationEthereumDocumentStoreStatusCode.CONTRACT_NOT_FOUND],
message: `Contract ${address} was not found`,
};
};
const contractAddressInvalid = (address: Hash): Reason => {
return {
code: OpenAttestationEthereumDocumentStoreIssuedCode.CONTRACT_ADDRESS_INVALID,
code: OpenAttestationEthereumDocumentStoreStatusCode.CONTRACT_ADDRESS_INVALID,
codeString:
OpenAttestationEthereumDocumentStoreIssuedCode[
OpenAttestationEthereumDocumentStoreIssuedCode.CONTRACT_ADDRESS_INVALID
OpenAttestationEthereumDocumentStoreStatusCode[
OpenAttestationEthereumDocumentStoreStatusCode.CONTRACT_ADDRESS_INVALID
],
message: `Contract address ${address} is invalid`,
};
};
export const contractNotIssued = (merkleRoot: Hash, address: string): Reason => {
return {
code: OpenAttestationEthereumDocumentStoreIssuedCode.DOCUMENT_NOT_ISSUED,
code: OpenAttestationEthereumDocumentStoreStatusCode.DOCUMENT_NOT_ISSUED,
codeString:
OpenAttestationEthereumDocumentStoreIssuedCode[
OpenAttestationEthereumDocumentStoreIssuedCode.DOCUMENT_NOT_ISSUED
OpenAttestationEthereumDocumentStoreStatusCode[
OpenAttestationEthereumDocumentStoreStatusCode.DOCUMENT_NOT_ISSUED
],
message: `Certificate ${merkleRoot} has not been issued under contract ${address}`,
message: `Document ${merkleRoot} has not been issued under contract ${address}`,
};
};

export const contractRevoked = (merkleRoot: string, address: string): Reason => {
return {
code: OpenAttestationEthereumDocumentStoreRevokedCode.DOCUMENT_REVOKED,
code: OpenAttestationEthereumDocumentStoreStatusCode.DOCUMENT_REVOKED,
codeString:
OpenAttestationEthereumDocumentStoreRevokedCode[OpenAttestationEthereumDocumentStoreRevokedCode.DOCUMENT_REVOKED],
message: `Certificate ${merkleRoot} has been revoked under contract ${address}`,
OpenAttestationEthereumDocumentStoreStatusCode[OpenAttestationEthereumDocumentStoreStatusCode.DOCUMENT_REVOKED],
message: `Document ${merkleRoot} has been revoked under contract ${address}`,
};
};

Expand All @@ -64,10 +58,10 @@ export const getErrorReason = (error: EthersError, address: string): Reason | nu
}
return {
message: `Error with smart contract ${address}: ${error.reason}`,
code: OpenAttestationEthereumDocumentStoreIssuedCode.ETHERS_UNHANDLED_ERROR,
code: OpenAttestationEthereumDocumentStoreStatusCode.ETHERS_UNHANDLED_ERROR,
codeString:
OpenAttestationEthereumDocumentStoreIssuedCode[
OpenAttestationEthereumDocumentStoreIssuedCode.ETHERS_UNHANDLED_ERROR
OpenAttestationEthereumDocumentStoreStatusCode[
OpenAttestationEthereumDocumentStoreStatusCode.ETHERS_UNHANDLED_ERROR
],
};
};
15 changes: 6 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,16 @@ import { verificationBuilder } from "./verifiers/verificationBuilder";
import { Verifier, Verifiers } from "./types/core";
import { openAttestationHash } from "./verifiers/hash/openAttestationHash";
import { Identity, openAttestationDnsTxt } from "./verifiers/dnsText/openAttestationDnsTxt";
import { openAttestationEthereumDocumentStoreIssued } from "./verifiers/documentStoreIssued/openAttestationEthereumDocumentStoreIssued";
import { openAttestationSignedProof } from "./verifiers/signedProof/openAttestationSignedProof";
import { openAttestationEthereumDocumentStoreRevoked } from "./verifiers/documentStoreRevoked/openAttestationEthereumDocumentStoreRevoked";
import { isValid } from "./validator";
import { openAttestationEthereumTokenRegistryMinted } from "./verifiers/tokenRegistryMinted/openAttestationEthereumTokenRegistryMinted";
import { openAttestationEthereumTokenRegistryStatus } from "./verifiers/tokenRegistryStatus/openAttestationEthereumTokenRegistryStatus";
import { openAttestationEthereumDocumentStoreStatus } from "./verifiers/documentStoreStatus/openAttestationEthereumDocumentStoreStatus";

const openAttestationVerifiers: Verifiers[] = [
openAttestationHash,
openAttestationSignedProof,
openAttestationEthereumDocumentStoreIssued,
openAttestationEthereumTokenRegistryMinted,
openAttestationEthereumDocumentStoreRevoked,
openAttestationEthereumTokenRegistryStatus,
openAttestationEthereumDocumentStoreStatus,
openAttestationDnsTxt,
];

Expand All @@ -34,9 +32,8 @@ export {
Verifier,
Identity,
openAttestationHash,
openAttestationEthereumDocumentStoreRevoked,
openAttestationSignedProof,
openAttestationEthereumDocumentStoreIssued,
openAttestationDnsTxt,
openAttestationEthereumTokenRegistryMinted,
openAttestationEthereumDocumentStoreStatus,
openAttestationEthereumTokenRegistryStatus,
};
13 changes: 3 additions & 10 deletions src/types/error.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// NEVER EVER REPLACE OR CHANGE A VALUE :)
// code for errors and invalid fragment
export enum OpenAttestationEthereumDocumentStoreIssuedCode {
export enum OpenAttestationEthereumDocumentStoreStatusCode {
UNEXPECTED_ERROR = 0,
DOCUMENT_NOT_ISSUED = 1,
CONTRACT_ADDRESS_INVALID = 2,
ETHERS_UNHANDLED_ERROR = 3,
SKIPPED = 4,
DOCUMENT_REVOKED = 5,
CONTRACT_NOT_FOUND = 404,
}
export enum OpenAttestationDocumentSignedCode {
Expand All @@ -14,15 +15,7 @@ export enum OpenAttestationDocumentSignedCode {
DOCUMENT_PROOF_ERROR = 2,
SKIPPED = 4,
}
export enum OpenAttestationEthereumDocumentStoreRevokedCode {
UNEXPECTED_ERROR = 0,
DOCUMENT_REVOKED = 1,
CONTRACT_ADDRESS_INVALID = 2,
ETHERS_UNHANDLED_ERROR = 3,
SKIPPED = 4,
CONTRACT_NOT_FOUND = 404,
}
export enum OpenAttestationEthereumTokenRegistryMintedCode {
export enum OpenAttestationEthereumTokenRegistryStatusCode {
UNEXPECTED_ERROR = 0,
DOCUMENT_NOT_MINTED = 1,
CONTRACT_ADDRESS_INVALID = 2,
Expand Down
4 changes: 2 additions & 2 deletions src/verifiers/dnsText/openAttestationDnsTxt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export const openAttestationDnsTxt: Verifier<
reason: {
code: OpenAttestationDnsTxtCode.INVALID_IDENTITY,
codeString: OpenAttestationDnsTxtCode[OpenAttestationDnsTxtCode.INVALID_IDENTITY],
message: `Certificate issuer identity for ${smartContractAddress} is invalid`,
message: `Document issuer identity for ${smartContractAddress} is invalid`,
},
status: "INVALID",
};
Expand All @@ -135,7 +135,7 @@ export const openAttestationDnsTxt: Verifier<
reason: {
code: OpenAttestationDnsTxtCode.INVALID_IDENTITY,
codeString: OpenAttestationDnsTxtCode[OpenAttestationDnsTxtCode.INVALID_IDENTITY],
message: "Certificate issuer identity is invalid",
message: "Document issuer identity is invalid",
},
status: "INVALID",
};
Expand Down
4 changes: 2 additions & 2 deletions src/verifiers/dnsText/openAttestationDnsTxt.v2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ describe("OpenAttestationDnsTxt v2 document", () => {
reason: {
code: 1,
codeString: "INVALID_IDENTITY",
message: "Certificate issuer identity for 0xabcd is invalid",
message: "Document issuer identity for 0xabcd is invalid",
},
status: "INVALID",
},
Expand Down Expand Up @@ -395,7 +395,7 @@ describe("OpenAttestationDnsTxt v2 document", () => {
reason: {
code: 1,
codeString: "INVALID_IDENTITY",
message: "Certificate issuer identity for 0xabcd is invalid",
message: "Document issuer identity for 0xabcd is invalid",
},
status: "INVALID",
},
Expand Down
2 changes: 1 addition & 1 deletion src/verifiers/dnsText/openAttestationDnsTxt.v3.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe("OpenAttestationDnsTxt v3 document", () => {
reason: {
code: 1,
codeString: "INVALID_IDENTITY",
message: "Certificate issuer identity is invalid",
message: "Document issuer identity is invalid",
},
status: "INVALID",
});
Expand Down
Loading

0 comments on commit 714b0ef

Please sign in to comment.