From 286b6bb3dda15eccc7e6594a5c0855ee54f52516 Mon Sep 17 00:00:00 2001 From: Nebulis Date: Thu, 9 Jan 2020 12:36:12 +0800 Subject: [PATCH] fix: type dns verifier data --- src/types/core.ts | 5 +-- src/verifiers/openAttestationDnsTxt.ts | 31 ++++++++----------- .../openAttestationDnsTxt.v2.test.ts | 19 ++++++++---- .../openAttestationDnsTxt.v3.test.ts | 4 +-- src/verify.v2.integration.test.ts | 4 +-- src/verify.v3.integration.test.ts | 10 +++--- 6 files changed, 38 insertions(+), 35 deletions(-) diff --git a/src/types/core.ts b/src/types/core.ts index 955c2e5c..3251c4b4 100644 --- a/src/types/core.ts +++ b/src/types/core.ts @@ -50,11 +50,12 @@ interface SkippedVerificationFragment extends VerificationFragment { } export interface Verifier< Document = WrappedDocument | WrappedDocument, - Options = VerificationManagerOptions + Options = VerificationManagerOptions, + Data = any > { skip: (document: Document, options: Options) => Promise; test: (document: Document, options: Options) => boolean; - verify: (document: Document, options: Options) => Promise; + verify: (document: Document, options: Options) => Promise>; } export type Hash = string; diff --git a/src/verifiers/openAttestationDnsTxt.ts b/src/verifiers/openAttestationDnsTxt.ts index 3a52ad5b..98be7491 100644 --- a/src/verifiers/openAttestationDnsTxt.ts +++ b/src/verifiers/openAttestationDnsTxt.ts @@ -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 ( @@ -35,11 +30,12 @@ const resolveIssuerIdentity = async ( return matchingRecord ? { status: "VALID", - dns: location, + location, value: smartContractAddress } : { status: "INVALID", + location, value: smartContractAddress }; }; @@ -47,7 +43,9 @@ const resolveIssuerIdentity = async ( const name = "OpenAttestationDnsTxt"; const type: VerificationFragmentType = "ISSUER_IDENTITY"; export const openAttestationDnsTxt: Verifier< - WrappedDocument | WrappedDocument + WrappedDocument | WrappedDocument, + VerificationManagerOptions, + Identity | Identity[] > = { skip: () => { return Promise.resolve({ @@ -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) }) ); @@ -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" }; diff --git a/src/verifiers/openAttestationDnsTxt.v2.test.ts b/src/verifiers/openAttestationDnsTxt.v2.test.ts index b91f5e8c..e8f19ca0 100644 --- a/src/verifiers/openAttestationDnsTxt.v2.test.ts +++ b/src/verifiers/openAttestationDnsTxt.v2.test.ts @@ -15,7 +15,7 @@ describe("OpenAttestationDnsTxt v2 document", () => { name: "OpenAttestationDnsTxt", data: [ { - dns: "example.tradetrust.io", + location: "example.tradetrust.io", status: "VALID", value: "0xe59877ac86c0310e9ddaeb627f42fdee5f793fbe" } @@ -51,7 +51,7 @@ describe("OpenAttestationDnsTxt v2 document", () => { name: "OpenAttestationDnsTxt", data: [ { - dns: "example.tradetrust.io", + location: "example.tradetrust.io", status: "VALID", value: "0xe59877ac86c0310e9ddaeb627f42fdee5f793fbe" } @@ -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" } @@ -270,7 +276,7 @@ describe("OpenAttestationDnsTxt v2 document", () => { status: "SKIPPED" }, { - dns: "example.tradetrust.io", + location: "example.tradetrust.io", status: "VALID", value: "0xe59877ac86c0310e9ddaeb627f42fdee5f793fbe" } @@ -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" } @@ -352,7 +359,7 @@ describe("OpenAttestationDnsTxt v2 document", () => { name: "OpenAttestationDnsTxt", data: [ { - dns: "example.tradetrust.io", + location: "example.tradetrust.io", status: "VALID", value: "0xe59877ac86c0310e9ddaeb627f42fdee5f793fbe" }, diff --git a/src/verifiers/openAttestationDnsTxt.v3.test.ts b/src/verifiers/openAttestationDnsTxt.v3.test.ts index 6aa83424..7715c52f 100644 --- a/src/verifiers/openAttestationDnsTxt.v3.test.ts +++ b/src/verifiers/openAttestationDnsTxt.v3.test.ts @@ -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" }, @@ -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" }); diff --git a/src/verify.v2.integration.test.ts b/src/verify.v2.integration.test.ts index e50724cf..2288bfbf 100644 --- a/src/verify.v2.integration.test.ts +++ b/src/verify.v2.integration.test.ts @@ -230,7 +230,7 @@ describe("verify(integration)", () => { { data: [ { - dns: "example.tradetrust.io", + location: "example.tradetrust.io", status: "VALID", value: "0xe59877ac86c0310e9ddaeb627f42fdee5f793fbe" } @@ -289,7 +289,7 @@ describe("verify(integration)", () => { { data: [ { - dns: "tradetrust.io", + location: "tradetrust.io", status: "VALID", value: "0x48399Fb88bcD031C556F53e93F690EEC07963Af3" } diff --git a/src/verify.v3.integration.test.ts b/src/verify.v3.integration.test.ts index eaaaf888..af049adc 100644 --- a/src/verify.v3.integration.test.ts +++ b/src/verify.v3.integration.test.ts @@ -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", @@ -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", @@ -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", @@ -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", @@ -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",