Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: Open-Attestation/oa-verify
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v3.3.0
Choose a base ref
...
head repository: Open-Attestation/oa-verify
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v3.4.0
Choose a head ref
  • 4 commits
  • 5 files changed
  • 1 contributor

Commits on Jun 17, 2020

  1. chore: update readme

    Nebulis authored Jun 17, 2020
    Copy the full SHA
    c235339 View commit details

Commits on Jun 23, 2020

  1. Copy the full SHA
    de40581 View commit details

Commits on Jul 4, 2020

  1. feat: allow custom api key

    Nebulis committed Jul 4, 2020
    Copy the full SHA
    523956c View commit details
  2. Copy the full SHA
    8af3c5c View commit details
Showing with 245 additions and 4 deletions.
  1. +3 −2 README.md
  2. +1 −1 src/common/smartContract/contractInstance.ts
  3. +2 −1 src/config.ts
  4. +171 −0 src/verify.v2.integration.test.ts
  5. +68 −0 test/fixtures/v2/documentRinkebyWithDocumentStore.ts
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -16,8 +16,9 @@ npm install @govtechsg/oa-verify
import { documentRopstenValidWithToken } from "./test/fixtures/v2/documentRopstenValidWithToken";
import { verify, isValid } from "@govtechsg/oa-verify";

verify(documentRopstenValidWithToken, { network: "ropsten" }).then(console.log); // see below
console.log(isValid(results)); // display true
const fragments = await verify(documentRopstenValidWithToken, { network: "ropsten" });
console.log(fragments); // see below
console.log(isValid(fragments)); // display true
```

```json
2 changes: 1 addition & 1 deletion src/common/smartContract/contractInstance.ts
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ interface ContractInstance {
}

export const getProvider = (options: { network: string }): ethers.providers.Provider =>
new ethers.providers.InfuraProvider(options.network, INFURA_API_KEY);
new ethers.providers.InfuraProvider(options.network, process?.env?.INFURA_API_KEY || INFURA_API_KEY);

export const contractInstance = (options: ContractInstance) => {
const contract = new ethers.Contract(options.contractAddress, options.abi, getProvider(options));
3 changes: 2 additions & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export const INFURA_API_KEY = "92c9a51428b946c1b8c1ac5a237616e4";
// export const INFURA_API_KEY = "92c9a51428b946c1b8c1ac5a237616e4";
export const INFURA_API_KEY = "9f83339cff8c408093a75f98e0001b1a";
171 changes: 171 additions & 0 deletions src/verify.v2.integration.test.ts
Original file line number Diff line number Diff line change
@@ -14,6 +14,10 @@ import { documentRopstenRevokedWithToken } from "../test/fixtures/v2/documentRop
import { documentRopstenRevokedWithDocumentStore } from "../test/fixtures/v2/documentRopstenRevokedWithDocumentStore";
import { documentSignedProofValid } from "../test/fixtures/v2/documentSignedProofValid";
import { documentSignedProofInvalidSignature } from "../test/fixtures/v2/documentSignedProofInvalidSignature";
import {
documentRinkebyRevokedWithDocumentStore,
documentRinkebyValidWithDocumentStore,
} from "../test/fixtures/v2/documentRinkebyWithDocumentStore";

describe("verify(integration)", () => {
it("should fail for everything when document's hash is invalid and certificate store is invalid", async () => {
@@ -741,4 +745,171 @@ describe("verify(integration)", () => {
expect(isValid(results)).toStrictEqual(false);
expect(isValid(results, ["DOCUMENT_STATUS"])).toStrictEqual(false);
});

it("should should work when document with document store has been issued to rinkeby network", async () => {
const results = await verify(documentRinkebyValidWithDocumentStore, {
network: "rinkeby",
});

expect(results).toStrictEqual([
{
type: "DOCUMENT_INTEGRITY",
name: "OpenAttestationHash",
data: true,
status: "VALID",
},
{
name: "OpenAttestationSignedProof",
reason: {
code: 4,
codeString: "SKIPPED",
message: "Document does not have a proof block",
},
status: "SKIPPED",
type: "DOCUMENT_STATUS",
},
{
name: "OpenAttestationEthereumDocumentStoreIssued",
type: "DOCUMENT_STATUS",
data: {
issuedOnAll: true,
details: [
{
issued: true,
address: "0x718B518565B81097b185661EBba3966Ff32A0039",
},
],
},
status: "VALID",
},
{
status: "SKIPPED",
type: "DOCUMENT_STATUS",
name: "OpenAttestationEthereumTokenRegistryMinted",
reason: {
code: 4,
codeString: "SKIPPED",
message: 'Document issuers doesn\'t have "tokenRegistry" property or TOKEN_REGISTRY method',
},
},
{
name: "OpenAttestationEthereumDocumentStoreRevoked",
type: "DOCUMENT_STATUS",
data: {
revokedOnAny: false,
details: [
{
revoked: false,
address: "0x718B518565B81097b185661EBba3966Ff32A0039",
},
],
},
status: "VALID",
},
{
name: "OpenAttestationDnsTxt",
type: "ISSUER_IDENTITY",
data: [
{
status: "VALID",
location: "example.openattestation.com",
value: "0x718B518565B81097b185661EBba3966Ff32A0039",
},
],
status: "VALID",
},
]);
expect(isValid(results)).toStrictEqual(true);
});

it("should should work when document with document store has been issued and revoked to rinkeby network", async () => {
const results = await verify(documentRinkebyRevokedWithDocumentStore, {
network: "rinkeby",
});

expect(results).toStrictEqual([
{
type: "DOCUMENT_INTEGRITY",
name: "OpenAttestationHash",
data: true,
status: "VALID",
},
{
name: "OpenAttestationSignedProof",
reason: {
code: 4,
codeString: "SKIPPED",
message: "Document does not have a proof block",
},
status: "SKIPPED",
type: "DOCUMENT_STATUS",
},
{
name: "OpenAttestationEthereumDocumentStoreIssued",
type: "DOCUMENT_STATUS",
data: {
issuedOnAll: true,
details: [
{
issued: true,
address: "0x718B518565B81097b185661EBba3966Ff32A0039",
},
],
},
status: "VALID",
},
{
status: "SKIPPED",
type: "DOCUMENT_STATUS",
name: "OpenAttestationEthereumTokenRegistryMinted",
reason: {
code: 4,
codeString: "SKIPPED",
message: 'Document issuers doesn\'t have "tokenRegistry" property or TOKEN_REGISTRY method',
},
},
{
name: "OpenAttestationEthereumDocumentStoreRevoked",
type: "DOCUMENT_STATUS",
data: {
revokedOnAny: true,
details: [
{
revoked: true,
address: "0x718B518565B81097b185661EBba3966Ff32A0039",
reason: {
code: 1,
codeString: "DOCUMENT_REVOKED",
message:
"Certificate 0x92c04840038856f29890720bb57db655b9131ad2f93cf29cefcf17ea84dfb7d5 has been revoked under contract 0x718B518565B81097b185661EBba3966Ff32A0039",
},
},
],
},
status: "INVALID",
reason: {
code: 1,
codeString: "DOCUMENT_REVOKED",
message:
"Certificate 0x92c04840038856f29890720bb57db655b9131ad2f93cf29cefcf17ea84dfb7d5 has been revoked under contract 0x718B518565B81097b185661EBba3966Ff32A0039",
},
},
{
name: "OpenAttestationDnsTxt",
type: "ISSUER_IDENTITY",
data: [
{
status: "VALID",
location: "example.openattestation.com",
value: "0x718B518565B81097b185661EBba3966Ff32A0039",
},
],
status: "VALID",
},
]);
expect(isValid(results)).toStrictEqual(false);
expect(isValid(results, ["DOCUMENT_STATUS"])).toStrictEqual(false);
expect(isValid(results, ["DOCUMENT_INTEGRITY"])).toStrictEqual(true);
expect(isValid(results, ["ISSUER_IDENTITY"])).toStrictEqual(true);
});
});
68 changes: 68 additions & 0 deletions test/fixtures/v2/documentRinkebyWithDocumentStore.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { SchemaId, v2, WrappedDocument } from "@govtechsg/open-attestation";

interface CustomDocument extends v2.OpenAttestationDocument {
name: string;
}
export const documentRinkebyValidWithDocumentStore: WrappedDocument<CustomDocument> = {
version: SchemaId.v2,
data: {
id: "de3e3e29-24b4-489e-8e63-03255e58e9c0:string:53b75bbe",
name: "0ca56c17-084b-4c52-8a56-5acfdd517800:string:Govtech Demo Certificate",
$template: {
name: "fd948b70-0e9a-4fe1-a288-a8deeb6c2b73:string:GOVTECH_DEMO",
type: "10458382-c7c5-4edd-a5da-8318b547df2e:string:EMBEDDED_RENDERER",
url: "0fb18658-670e-461f-938f-a5a10794fef7:string:https://demo-renderer.opencerts.io",
},
issuers: [
{
name: "e09d407e-54e7-4cb4-9704-9bde78fa3ba1:string:Govtech",
documentStore: "a6db3b26-b848-4f1f-b46b-b3dbcd0db332:string:0x718B518565B81097b185661EBba3966Ff32A0039",
identityProof: {
type: "2135cbfa-9714-46fc-b65e-464c1e1413bf:string:DNS-TXT",
location: "eed8cc31-5832-4d84-8b5d-504734bc647e:string:example.openattestation.com",
},
},
],
recipient: {
name: "78327e90-bc9e-4ff5-b4b7-797630bdfc63:string:Your Name",
},
},
signature: {
type: "SHA3MerkleProof",
targetHash: "723991dd29aaada73246da95106448b1b4c0fd41ad86cf0352177c4829f2f8de",
proof: [],
merkleRoot: "723991dd29aaada73246da95106448b1b4c0fd41ad86cf0352177c4829f2f8de",
},
};

export const documentRinkebyRevokedWithDocumentStore: WrappedDocument<CustomDocument> = {
version: SchemaId.v2,
data: {
id: "d8eb4e38-dc66-4d7d-8791-05348af674c2:string:53b75bbe",
name: "de3c2354-0693-4803-81d9-509f82792b7e:string:Govtech Demo Certificate",
$template: {
name: "06788de0-68dd-4cd4-a3e9-969886cbe040:string:GOVTECH_DEMO",
type: "c0ed52d4-b297-4696-bde9-51f3583b0249:string:EMBEDDED_RENDERER",
url: "43f124b3-2457-4759-bd4d-1d433bca8b02:string:https://demo-renderer.opencerts.io",
},
issuers: [
{
name: "ea753750-2e71-49e3-98d1-5a6a5f2ebebc:string:Govtech",
documentStore: "5c390b10-fcd5-4dc9-a399-8ec269676655:string:0x718B518565B81097b185661EBba3966Ff32A0039",
identityProof: {
type: "133055da-2743-41ee-aa22-d0a9b10248d8:string:DNS-TXT",
location: "b7b6fb65-01cf-4a48-9edf-d2ecc7665920:string:example.openattestation.com",
},
},
],
recipient: {
name: "85b1bb18-04b6-4e9f-9c9e-f2546ff4c1ac:string:Your Name",
},
},
signature: {
type: "SHA3MerkleProof",
targetHash: "92c04840038856f29890720bb57db655b9131ad2f93cf29cefcf17ea84dfb7d5",
proof: [],
merkleRoot: "92c04840038856f29890720bb57db655b9131ad2f93cf29cefcf17ea84dfb7d5",
},
};