Skip to content

Commit

Permalink
feat: aligning naming convention with files and modules
Browse files Browse the repository at this point in the history
  • Loading branch information
yehjxraymond committed Nov 6, 2020
1 parent cf7a6a1 commit ce1dae6
Show file tree
Hide file tree
Showing 23 changed files with 599 additions and 579 deletions.
26 changes: 13 additions & 13 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@ import { SignedWrappedDocument, v2, v3, WrappedDocument } from "@govtechsg/open-
import { verificationBuilder } from "./verifiers/verificationBuilder";
import { Verifier, Verifiers } from "./types/core";
import { openAttestationHash } from "./verifiers/documentIntegrity/hash/openAttestationHash";
import { Identity, openAttestationDnsTxt } from "./verifiers/issuerIdentity/dnsText/openAttestationDnsTxt";
import { isValid } from "./validator";
import { openAttestationEthereumTokenRegistryStatus } from "./verifiers/documentStatus/tokenRegistryStatus/openAttestationEthereumTokenRegistryStatus";
import { openAttestationEthereumDocumentStoreStatus } from "./verifiers/documentStatus/documentStoreStatus/openAttestationEthereumDocumentStoreStatus";
import { OpenAttestationDidSignedDocumentStatus } from "./verifiers/documentStatus/didSignedDocumentStatus";
import { OpenAttestationDidSignedDidIdentityProof } from "./verifiers/issuerIdentity/didIdentityProof";
import { OpenAttestationDnsDid } from "./verifiers/issuerIdentity/dnsDidProof";
import { openAttestationEthereumTokenRegistryStatus } from "./verifiers/documentStatus/tokenRegistry";
import { openAttestationEthereumDocumentStoreStatus } from "./verifiers/documentStatus/documentStore";
import { openAttestationDidSignedDocumentStatus } from "./verifiers/documentStatus/didSigned";
import { Identity, openAttestationDnsTxtIdentityProof } from "./verifiers/issuerIdentity/dnsTxt";
import { openAttestationDidIdentityProof } from "./verifiers/issuerIdentity/did";
import { openAttestationDnsDidIdentityProof } from "./verifiers/issuerIdentity/dnsDid";

const openAttestationVerifiers: Verifiers[] = [
openAttestationHash,
openAttestationEthereumTokenRegistryStatus,
openAttestationEthereumDocumentStoreStatus,
openAttestationDnsTxt,
OpenAttestationDnsDid,
OpenAttestationDidSignedDocumentStatus,
openAttestationDidSignedDocumentStatus,
openAttestationDnsTxtIdentityProof,
openAttestationDnsDidIdentityProof,
];

const verify = verificationBuilder<
Expand All @@ -36,10 +36,10 @@ export {
Verifier,
Identity,
openAttestationHash,
openAttestationDnsTxt,
openAttestationEthereumDocumentStoreStatus,
openAttestationEthereumTokenRegistryStatus,
OpenAttestationDnsDid,
OpenAttestationDidSignedDocumentStatus,
OpenAttestationDidSignedDidIdentityProof,
openAttestationDidSignedDocumentStatus,
openAttestationDnsTxtIdentityProof,
openAttestationDnsDidIdentityProof,
openAttestationDidIdentityProof,
};
2 changes: 1 addition & 1 deletion src/types/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export enum OpenAttestationDidSignedDocumentStatusCode {
UNSIGNED = 3,
INVALID_ISSUERS = 4,
}
export enum OpenAttestationDidSignedDidIdentityProofCode {
export enum OpenAttestationDidCode {
SKIPPED = 0,
UNEXPECTED_ERROR = 1,
INVALID_ISSUERS = 2,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { OpenAttestationDidSignedDocumentStatus } from "./didSignedDocumentStatus";
import { openAttestationDidSignedDocumentStatus } from "./didSignedDocumentStatus";
import { documentRopstenValidWithDocumentStore } from "../../../../test/fixtures/v2/documentRopstenValidWithDocumentStore";
import { documentDidSigned } from "../../../../test/fixtures/v2/documentDidSigned";
import { documentDnsDidSigned } from "../../../../test/fixtures/v2/documentDnsDidSigned";
Expand Down Expand Up @@ -31,7 +31,7 @@ const options = {

describe("skip", () => {
it("should return skip message", async () => {
const message = await OpenAttestationDidSignedDocumentStatus.skip(undefined as any, undefined as any);
const message = await openAttestationDidSignedDocumentStatus.skip(undefined as any, undefined as any);
expect(message).toMatchInlineSnapshot(`
Object {
"name": "OpenAttestationDidSignedDocumentStatus",
Expand All @@ -50,16 +50,16 @@ describe("skip", () => {
describe("test", () => {
describe("v2", () => {
it("should return false for documents not signed by DID", () => {
expect(OpenAttestationDidSignedDocumentStatus.test(documentRopstenValidWithDocumentStore, options)).toBe(false);
expect(OpenAttestationDidSignedDocumentStatus.test(documentRopstenNotIssuedWithTokenRegistry, options)).toBe(
expect(openAttestationDidSignedDocumentStatus.test(documentRopstenValidWithDocumentStore, options)).toBe(false);
expect(openAttestationDidSignedDocumentStatus.test(documentRopstenNotIssuedWithTokenRegistry, options)).toBe(
false
);
});
it("should return true for documents where any issuer is using the `DID` identity proof", () => {
expect(OpenAttestationDidSignedDocumentStatus.test(documentDidSigned, options)).toBe(true);
expect(openAttestationDidSignedDocumentStatus.test(documentDidSigned, options)).toBe(true);
});
it("should return true for documents where any issuer is using the `DNS-DID` identity proof", () => {
expect(OpenAttestationDidSignedDocumentStatus.test(documentDnsDidSigned, options)).toBe(true);
expect(openAttestationDidSignedDocumentStatus.test(documentDnsDidSigned, options)).toBe(true);
});
});
});
Expand All @@ -71,7 +71,7 @@ describe("verify", () => {
describe("v2", () => {
it("should pass for documents using `DID` and is correctly signed", async () => {
whenPublicKeyResolvesSuccessfully();
const res = await OpenAttestationDidSignedDocumentStatus.verify(documentDidSigned, options);
const res = await openAttestationDidSignedDocumentStatus.verify(documentDidSigned, options);
expect(res).toMatchInlineSnapshot(`
Object {
"data": Object {
Expand All @@ -94,7 +94,7 @@ describe("verify", () => {
});
it("should pass for documents using `DID-DNS` and is correctly signed", async () => {
whenPublicKeyResolvesSuccessfully();
const res = await OpenAttestationDidSignedDocumentStatus.verify(documentDnsDidSigned, options);
const res = await openAttestationDidSignedDocumentStatus.verify(documentDnsDidSigned, options);
expect(res).toMatchInlineSnapshot(`
Object {
"data": Object {
Expand All @@ -117,7 +117,7 @@ describe("verify", () => {
});
it("should fail when revocation block is missing", async () => {
whenPublicKeyResolvesSuccessfully();
const res = await OpenAttestationDidSignedDocumentStatus.verify(documentDidObfuscatedRevocation, options);
const res = await openAttestationDidSignedDocumentStatus.verify(documentDidObfuscatedRevocation, options);
expect(res).toMatchInlineSnapshot(`
Object {
"data": [Error: revocation block not found for an issuer],
Expand All @@ -134,7 +134,7 @@ describe("verify", () => {
});
it("should fail when revocation is not set to NONE (for now)", async () => {
whenPublicKeyResolvesSuccessfully();
const res = await OpenAttestationDidSignedDocumentStatus.verify(documentDidCustomRevocation, options);
const res = await openAttestationDidSignedDocumentStatus.verify(documentDidCustomRevocation, options);
expect(res).toMatchInlineSnapshot(`
Object {
"data": Object {
Expand All @@ -157,7 +157,7 @@ describe("verify", () => {
});
it("should fail when proof is missing", async () => {
whenPublicKeyResolvesSuccessfully();
const res = await OpenAttestationDidSignedDocumentStatus.verify(documentDidMissingProof, options);
const res = await openAttestationDidSignedDocumentStatus.verify(documentDidMissingProof, options);
expect(res).toMatchInlineSnapshot(`
Object {
"data": [Error: Only signed v2 is supported now],
Expand All @@ -174,7 +174,7 @@ describe("verify", () => {
});
it("should fail when did resolver fails for some reasons", async () => {
mockGetPublicKey.mockRejectedValue(new Error("Error from DID resolver"));
const res = await OpenAttestationDidSignedDocumentStatus.verify(documentDidSigned, options);
const res = await openAttestationDidSignedDocumentStatus.verify(documentDidSigned, options);
expect(res).toMatchInlineSnapshot(`
Object {
"data": [Error: Error from DID resolver],
Expand All @@ -191,7 +191,7 @@ describe("verify", () => {
});
it("should fail when corresponding proof to key is not found in proof", async () => {
whenPublicKeyResolvesSuccessfully();
const res = await OpenAttestationDidSignedDocumentStatus.verify({ ...documentDidSigned, proof: [] }, options);
const res = await openAttestationDidSignedDocumentStatus.verify({ ...documentDidSigned, proof: [] }, options);
expect(res).toMatchInlineSnapshot(`
Object {
"data": [Error: Proof not found for did:ethr:0xE712878f6E8d5d4F9e87E10DA604F9cB564C9a89#controller],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ const verify: VerifierType["verify"] = withCodedErrorHandler(
}
);

export const OpenAttestationDidSignedDocumentStatus: VerifierType = {
export const openAttestationDidSignedDocumentStatus: VerifierType = {
skip,
test,
verify,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { openAttestationEthereumDocumentStoreStatus } from "./openAttestationEthereumDocumentStoreStatus";
import { openAttestationEthereumDocumentStoreStatus } from "./ethereumDocumentStoreStatus";
import { documentRopstenRevokedWithDocumentStore } from "../../../../test/fixtures/v2/documentRopstenRevokedWithDocumentStore";
import { documentRopstenRevokedWithCertificateStore } from "../../../../test/fixtures/v2/documentRopstenRevokedWithCertificateStore";
import { documentRopstenNotIssuedWithCertificateStore } from "../../../../test/fixtures/v2/documentRopstenNotIssuedWithCertificateStore";
Expand Down
1 change: 1 addition & 0 deletions src/verifiers/documentStatus/documentStore/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./ethereumDocumentStoreStatus";
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { openAttestationEthereumTokenRegistryStatus } from "./openAttestationEthereumTokenRegistryStatus";
import { openAttestationEthereumTokenRegistryStatus } from "./ethereumTokenRegistryStatus";
import { documentRopstenNotIssuedWithTokenRegistry } from "../../../../test/fixtures/v2/documentRopstenNotIssuedWithTokenRegistry";
import { documentRopstenValidWithToken } from "../../../../test/fixtures/v2/documentRopstenValidWithToken";
import { documentRopstenValidWithTokenRegistry as v3documentRopstenValidWithTokenRegistry } from "../../../../test/fixtures/v3/documentRopstenValid";
Expand Down
1 change: 1 addition & 0 deletions src/verifiers/documentStatus/tokenRegistry/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./ethereumTokenRegistryStatus";
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { OpenAttestationDidSignedDidIdentityProof } from "./didIdentityProof";
import { openAttestationDidIdentityProof } from "./didIdentityProof";
import { documentRopstenValidWithDocumentStore } from "../../../../test/fixtures/v2/documentRopstenValidWithDocumentStore";
import { documentDidSigned } from "../../../../test/fixtures/v2/documentDidSigned";
import { documentDidWrongSignature } from "../../../../test/fixtures/v2/documentDidWrongSignature";
Expand All @@ -12,10 +12,10 @@ const options = {

describe("skip", () => {
it("should return skip message", async () => {
const message = await OpenAttestationDidSignedDidIdentityProof.skip(undefined as any, undefined as any);
const message = await openAttestationDidIdentityProof.skip(undefined as any, undefined as any);
expect(message).toMatchInlineSnapshot(`
Object {
"name": "OpenAttestationDidSignedDidIdentityProof",
"name": "OpenAttestationDidIdentityProof",
"reason": Object {
"code": 0,
"codeString": "SKIPPED",
Expand All @@ -31,21 +31,21 @@ describe("skip", () => {
describe("test", () => {
describe("v2", () => {
it("should return false for documents not using DID as top level identifier", () => {
expect(OpenAttestationDidSignedDidIdentityProof.test(documentRopstenValidWithDocumentStore, options)).toBe(false);
expect(openAttestationDidIdentityProof.test(documentRopstenValidWithDocumentStore, options)).toBe(false);
});
it("should return true for documents where any issuer is using the `DID` identity proof", () => {
expect(OpenAttestationDidSignedDidIdentityProof.test(documentDidSigned, options)).toBe(true);
expect(openAttestationDidIdentityProof.test(documentDidSigned, options)).toBe(true);
});
it("should return false for documents where any issuer is using the `DNS-DID` identity proof", () => {
expect(OpenAttestationDidSignedDidIdentityProof.test(documentDnsDidSigned, options)).toBe(false);
expect(openAttestationDidIdentityProof.test(documentDnsDidSigned, options)).toBe(false);
});
});
});

describe("verify", () => {
describe("v2", () => {
it("should pass for documents using `DID` and did signature is correct", async () => {
const verificationFragment = await OpenAttestationDidSignedDidIdentityProof.verify(documentDidSigned, options);
const verificationFragment = await openAttestationDidIdentityProof.verify(documentDidSigned, options);
expect(verificationFragment).toMatchInlineSnapshot(`
Object {
"data": Array [
Expand All @@ -54,17 +54,14 @@ describe("verify", () => {
"status": "VALID",
},
],
"name": "OpenAttestationDidSignedDidIdentityProof",
"name": "OpenAttestationDidIdentityProof",
"status": "VALID",
"type": "ISSUER_IDENTITY",
}
`);
});
it("should fail for documents using `DID` and did signature is not correct", async () => {
const verificationFragment = await OpenAttestationDidSignedDidIdentityProof.verify(
documentDidWrongSignature,
options
);
const verificationFragment = await openAttestationDidIdentityProof.verify(documentDidWrongSignature, options);
expect(verificationFragment).toMatchInlineSnapshot(`
Object {
"data": Array [
Expand All @@ -73,17 +70,14 @@ describe("verify", () => {
"status": "INVALID",
},
],
"name": "OpenAttestationDidSignedDidIdentityProof",
"name": "OpenAttestationDidIdentityProof",
"status": "INVALID",
"type": "ISSUER_IDENTITY",
}
`);
});
it("should fail for documents with other issuers", async () => {
const verificationFragment = await OpenAttestationDidSignedDidIdentityProof.verify(
documentDidMixedTokenRegistry,
options
);
const verificationFragment = await openAttestationDidIdentityProof.verify(documentDidMixedTokenRegistry, options);
expect(verificationFragment).toMatchInlineSnapshot(`
Object {
"data": Array [
Expand All @@ -100,7 +94,7 @@ describe("verify", () => {
"status": "INVALID",
},
],
"name": "OpenAttestationDidSignedDidIdentityProof",
"name": "OpenAttestationDidIdentityProof",
"status": "INVALID",
"type": "ISSUER_IDENTITY",
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { v2, v3, WrappedDocument, getData, utils } from "@govtechsg/open-attestation";
import { VerificationFragmentType, Verifier } from "../../../types/core";
import { OpenAttestationDidSignedDidIdentityProofCode } from "../../../types/error";
import { OpenAttestationDidCode } from "../../../types/error";
import { verifySignature } from "../../../did/verifier";
import { withCodedErrorHandler } from "../../../common/errorHandler";

const name = "OpenAttestationDidSignedDidIdentityProof";
const name = "OpenAttestationDidIdentityProof";
const type: VerificationFragmentType = "ISSUER_IDENTITY";
type VerifierType = Verifier<WrappedDocument<v2.OpenAttestationDocument> | WrappedDocument<v3.OpenAttestationDocument>>;

Expand All @@ -14,8 +14,8 @@ const skip: VerifierType["skip"] = async () => {
type,
name,
reason: {
code: OpenAttestationDidSignedDidIdentityProofCode.SKIPPED,
codeString: OpenAttestationDidSignedDidIdentityProofCode[OpenAttestationDidSignedDidIdentityProofCode.SKIPPED],
code: OpenAttestationDidCode.SKIPPED,
codeString: OpenAttestationDidCode[OpenAttestationDidCode.SKIPPED],
message: `Document is not using DID as top level identifier`,
},
};
Expand Down Expand Up @@ -52,9 +52,8 @@ const verify: VerifierType["verify"] = withCodedErrorHandler(
status: "INVALID",
reason: {
message: "Issuer is not using DID identityProof type",
code: OpenAttestationDidSignedDidIdentityProofCode.INVALID_ISSUERS,
codeString:
OpenAttestationDidSignedDidIdentityProofCode[OpenAttestationDidSignedDidIdentityProofCode.INVALID_ISSUERS],
code: OpenAttestationDidCode.INVALID_ISSUERS,
codeString: OpenAttestationDidCode[OpenAttestationDidCode.INVALID_ISSUERS],
},
};
});
Expand All @@ -73,13 +72,12 @@ const verify: VerifierType["verify"] = withCodedErrorHandler(
{
name,
type,
unexpectedErrorCode: OpenAttestationDidSignedDidIdentityProofCode.UNEXPECTED_ERROR,
unexpectedErrorString:
OpenAttestationDidSignedDidIdentityProofCode[OpenAttestationDidSignedDidIdentityProofCode.UNEXPECTED_ERROR],
unexpectedErrorCode: OpenAttestationDidCode.UNEXPECTED_ERROR,
unexpectedErrorString: OpenAttestationDidCode[OpenAttestationDidCode.UNEXPECTED_ERROR],
}
);

export const OpenAttestationDidSignedDidIdentityProof: VerifierType = {
export const openAttestationDidIdentityProof: VerifierType = {
skip,
test,
verify,
Expand Down
File renamed without changes.
Loading

0 comments on commit ce1dae6

Please sign in to comment.