Skip to content

Commit

Permalink
fix: type dns verifier data
Browse files Browse the repository at this point in the history
  • Loading branch information
Nebulis committed Jan 9, 2020
1 parent f4cf459 commit 286b6bb
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 35 deletions.
5 changes: 3 additions & 2 deletions src/types/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,12 @@ interface SkippedVerificationFragment extends VerificationFragment {
}
export interface Verifier<
Document = WrappedDocument<v3.OpenAttestationDocument> | WrappedDocument<v2.OpenAttestationDocument>,
Options = VerificationManagerOptions
Options = VerificationManagerOptions,
Data = any
> {
skip: (document: Document, options: Options) => Promise<SkippedVerificationFragment>;
test: (document: Document, options: Options) => boolean;
verify: (document: Document, options: Options) => Promise<VerificationFragment>;
verify: (document: Document, options: Options) => Promise<VerificationFragment<Data>>;
}
export type Hash = string;

Expand Down
31 changes: 13 additions & 18 deletions src/verifiers/openAttestationDnsTxt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,11 @@ import { getDocumentStoreRecords } from "@govtechsg/dnsprove";
import { utils } from "ethers";
import { isWrappedV2Document, VerificationFragmentType, VerificationManagerOptions, Verifier } from "../types/core";

type Identity =
| {
status: "VALID";
dns: string;
value: string;
}
| {
status: "INVALID";
value: string;
};
interface Identity {
status: "VALID" | "INVALID" | "SKIPPED";
location?: string;
value?: string;
}
// Resolve identity of an issuer, currently supporting only DNS-TXT
// DNS-TXT is explained => https://github.com/Open-Attestation/adr/blob/master/decentralized_identity_proof_DNS-TXT.md
const resolveIssuerIdentity = async (
Expand All @@ -35,19 +30,22 @@ const resolveIssuerIdentity = async (
return matchingRecord
? {
status: "VALID",
dns: location,
location,
value: smartContractAddress
}
: {
status: "INVALID",
location,
value: smartContractAddress
};
};

const name = "OpenAttestationDnsTxt";
const type: VerificationFragmentType = "ISSUER_IDENTITY";
export const openAttestationDnsTxt: Verifier<
WrappedDocument<v2.OpenAttestationDocument> | WrappedDocument<v3.OpenAttestationDocument>
WrappedDocument<v2.OpenAttestationDocument> | WrappedDocument<v3.OpenAttestationDocument>,
VerificationManagerOptions,
Identity | Identity[]
> = {
skip: () => {
return Promise.resolve({
Expand Down Expand Up @@ -82,9 +80,10 @@ export const openAttestationDnsTxt: Verifier<
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
return resolveIssuerIdentity(issuer, (issuer.documentStore || issuer.tokenRegistry)!, options);
}
return {
const skippedResponse: Identity = {
status: "SKIPPED"
};
return skippedResponse; // eslint is happy, so am I (https://github.com/bradzacher/eslint-plugin-typescript/blob/master/docs/rules/no-object-literal-type-assertion.md)
})
);

Expand Down Expand Up @@ -115,11 +114,7 @@ export const openAttestationDnsTxt: Verifier<
return {
name,
type,
data: {
type: documentData.issuer.identityProof.type,
location: documentData.issuer.identityProof.location,
value: documentData.proof.value
},
data: identity,
message: "Certificate issuer identity is invalid",
status: "INVALID"
};
Expand Down
19 changes: 13 additions & 6 deletions src/verifiers/openAttestationDnsTxt.v2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe("OpenAttestationDnsTxt v2 document", () => {
name: "OpenAttestationDnsTxt",
data: [
{
dns: "example.tradetrust.io",
location: "example.tradetrust.io",
status: "VALID",
value: "0xe59877ac86c0310e9ddaeb627f42fdee5f793fbe"
}
Expand Down Expand Up @@ -51,7 +51,7 @@ describe("OpenAttestationDnsTxt v2 document", () => {
name: "OpenAttestationDnsTxt",
data: [
{
dns: "example.tradetrust.io",
location: "example.tradetrust.io",
status: "VALID",
value: "0xe59877ac86c0310e9ddaeb627f42fdee5f793fbe"
}
Expand Down Expand Up @@ -80,7 +80,13 @@ describe("OpenAttestationDnsTxt v2 document", () => {
{
type: "ISSUER_IDENTITY",
name: "OpenAttestationDnsTxt",
data: [{ status: "INVALID", value: "0xabcd" }],
data: [
{
location: "example.tradetrust.io",
status: "INVALID",
value: "0xabcd"
}
],
message: "Certificate issuer identity for 0xabcd is invalid",
status: "INVALID"
}
Expand Down Expand Up @@ -270,7 +276,7 @@ describe("OpenAttestationDnsTxt v2 document", () => {
status: "SKIPPED"
},
{
dns: "example.tradetrust.io",
location: "example.tradetrust.io",
status: "VALID",
value: "0xe59877ac86c0310e9ddaeb627f42fdee5f793fbe"
}
Expand Down Expand Up @@ -314,11 +320,12 @@ describe("OpenAttestationDnsTxt v2 document", () => {
name: "OpenAttestationDnsTxt",
data: [
{
location: "example.tradetrust.io",
status: "INVALID",
value: "0xabcd"
},
{
dns: "example.tradetrust.io",
location: "example.tradetrust.io",
status: "VALID",
value: "0xe59877ac86c0310e9ddaeb627f42fdee5f793fbe"
}
Expand Down Expand Up @@ -352,7 +359,7 @@ describe("OpenAttestationDnsTxt v2 document", () => {
name: "OpenAttestationDnsTxt",
data: [
{
dns: "example.tradetrust.io",
location: "example.tradetrust.io",
status: "VALID",
value: "0xe59877ac86c0310e9ddaeb627f42fdee5f793fbe"
},
Expand Down
4 changes: 2 additions & 2 deletions src/verifiers/openAttestationDnsTxt.v3.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe("OpenAttestationDnsTxt v3 document", () => {
type: "ISSUER_IDENTITY",
name: "OpenAttestationDnsTxt",
data: {
dns: "example.openattestation.com",
location: "example.openattestation.com",
status: "VALID",
value: "0x8Fc57204c35fb9317D91285eF52D6b892EC08cD3"
},
Expand All @@ -39,7 +39,7 @@ describe("OpenAttestationDnsTxt v3 document", () => {
expect(fragment).toStrictEqual({
type: "ISSUER_IDENTITY",
name: "OpenAttestationDnsTxt",
data: { location: "some.io", value: "0x8Fc57204c35fb9317D91285eF52D6b892EC08cD3", type: "DNS-TXT" },
data: { location: "some.io", value: "0x8Fc57204c35fb9317D91285eF52D6b892EC08cD3", status: "INVALID" },
message: "Certificate issuer identity is invalid",
status: "INVALID"
});
Expand Down
4 changes: 2 additions & 2 deletions src/verify.v2.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ describe("verify(integration)", () => {
{
data: [
{
dns: "example.tradetrust.io",
location: "example.tradetrust.io",
status: "VALID",
value: "0xe59877ac86c0310e9ddaeb627f42fdee5f793fbe"
}
Expand Down Expand Up @@ -289,7 +289,7 @@ describe("verify(integration)", () => {
{
data: [
{
dns: "tradetrust.io",
location: "tradetrust.io",
status: "VALID",
value: "0x48399Fb88bcD031C556F53e93F690EEC07963Af3"
}
Expand Down
10 changes: 5 additions & 5 deletions src/verify.v3.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ describe("verify v3(integration)", () => {
{
data: {
location: "some.io",
type: "DNS-TXT",
status: "INVALID",
value: "0x8Fc57204c35fb9317D91285eF52D6b892EC08cD3"
},
message: "Certificate issuer identity is invalid",
Expand Down Expand Up @@ -116,7 +116,7 @@ describe("verify v3(integration)", () => {
{
data: {
location: "some.io",
type: "DNS-TXT",
status: "INVALID",
value: "0x8Fc57204c35fb9317D91285eF52D6b892EC08cD3"
},
message: "Certificate issuer identity is invalid",
Expand Down Expand Up @@ -177,7 +177,7 @@ describe("verify v3(integration)", () => {
{
data: {
location: "some.io",
type: "DNS-TXT",
status: "INVALID",
value: "0x8Fc57204c35fb9317D91285eF52D6b892EC08cD3"
},
message: "Certificate issuer identity is invalid",
Expand Down Expand Up @@ -237,7 +237,7 @@ describe("verify v3(integration)", () => {
{
data: {
location: "some.io",
type: "DNS-TXT",
status: "INVALID",
value: "0x8Fc57204c35fb9317D91285eF52D6b892EC08cD3"
},
message: "Certificate issuer identity is invalid",
Expand Down Expand Up @@ -292,7 +292,7 @@ describe("verify v3(integration)", () => {
{
data: {
location: "some.io",
type: "DNS-TXT",
status: "INVALID",
value: "0xb53499ee758352fAdDfCed863d9ac35C809E2F20"
},
message: "Certificate issuer identity is invalid",
Expand Down

0 comments on commit 286b6bb

Please sign in to comment.