Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: oav3 dns did #155

Merged
merged 4 commits into from
Jan 27, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/types/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export enum OpenAttestationDnsDidCode {
UNEXPECTED_ERROR = 1,
MALFORMED_IDENTITY_PROOF = 2,
INVALID_ISSUERS = 3,
UNSIGNED = 4,
}
export enum OpenAttestationSignatureCode {
UNEXPECTED_ERROR = 0,
Expand Down
2 changes: 1 addition & 1 deletion src/verifiers/issuerIdentity/did/didIdentityProof.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { v3 } from "@govtechsg/open-attestation";
import { openAttestationDidIdentityProof } from "./didIdentityProof";
import { documentRopstenValidWithDocumentStore } from "../../../../test/fixtures/v2/documentRopstenValidWithDocumentStore";
import { documentDidSigned } from "../../../../test/fixtures/v2/documentDidSigned";
Expand All @@ -10,7 +11,6 @@ import v3DidSignedRaw from "../../../../test/fixtures/v3/did-signed.json";
import v3DnsDidSignedRaw from "../../../../test/fixtures/v3/dnsdid-signed.json";
import v3DocumentStoreIssuedRaw from "../../../../test/fixtures/v3/documentStore-issued.json";
import v3TokenRegistryIssuedRaw from "../../../../test/fixtures/v3/tokenRegistry-issued.json";
import { v3 } from "@govtechsg/open-attestation";

const v3DidSigned = v3DidSignedRaw as v3.SignedWrappedDocument;
const v3DidWrapped = v3DidWrappedRaw as v3.WrappedDocument;
Expand Down
192 changes: 109 additions & 83 deletions src/verifiers/issuerIdentity/dnsDid/dnsDidProof.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
import { v3 } from "@govtechsg/open-attestation";
import { openAttestationDnsDidIdentityProof } from "./dnsDidProof";
import { documentRopstenValidWithDocumentStore } from "../../../../test/fixtures/v2/documentRopstenValidWithDocumentStore";
import { documentDidSigned } from "../../../../test/fixtures/v2/documentDidSigned";
import { documentDnsDidNoDnsTxt } from "../../../../test/fixtures/v2/documentDnsDidNoDnsTxt";
import { documentDnsDidSigned } from "../../../../test/fixtures/v2/documentDnsDidSigned";
import {
documentDnsDidMixedTokenRegistryValid,
documentDnsDidMixedTokenRegistryInvalid,
} from "../../../../test/fixtures/v2/documentDnsDidMixedTokenRegistry";
import { documentDnsDidMixedTokenRegistryValid } from "../../../../test/fixtures/v2/documentDnsDidMixedTokenRegistry";
import { getProvider } from "../../../common/utils";

import v3DnsDidWrappedRaw from "../../../../test/fixtures/v3/dnsdid-wrapped.json";
import v3DidSignedRaw from "../../../../test/fixtures/v3/did-signed.json";
import v3DnsDidSignedRaw from "../../../../test/fixtures/v3/dnsdid-signed.json";
import v3DocumentStoreIssuedRaw from "../../../../test/fixtures/v3/documentStore-issued.json";
import v3TokenRegistryIssuedRaw from "../../../../test/fixtures/v3/tokenRegistry-issued.json";

const v3DidSigned = v3DidSignedRaw as v3.SignedWrappedDocument;
const v3DnsDidWrapped = v3DnsDidWrappedRaw as v3.WrappedDocument;
const v3DnsDidSigned = v3DnsDidSignedRaw as v3.SignedWrappedDocument;
const v3DocumentStoreIssued = v3DocumentStoreIssuedRaw as v3.WrappedDocument;
const v3TokenRegistryIssued = v3TokenRegistryIssuedRaw as v3.WrappedDocument;

const options = {
provider: getProvider({ network: "ropsten" }),
};
Expand Down Expand Up @@ -43,98 +53,114 @@ describe("test", () => {
expect(openAttestationDnsDidIdentityProof.test(documentDnsDidSigned, options)).toBe(true);
});
});
describe("v3", () => {
it("should return true for document using `DNS-DID` top level identity proof", () => {
expect(openAttestationDnsDidIdentityProof.test(v3DnsDidSigned, options)).toBe(true);
expect(openAttestationDnsDidIdentityProof.test(v3DnsDidWrapped, options)).toBe(true);
});
it("should return false for document using `DID` top level identity proof", () => {
expect(openAttestationDnsDidIdentityProof.test(v3DidSigned, options)).toBe(false);
});
it("should return false for document using `DNS-TXT` top level identity proof", () => {
expect(openAttestationDnsDidIdentityProof.test(v3DocumentStoreIssued, options)).toBe(false);
expect(openAttestationDnsDidIdentityProof.test(v3TokenRegistryIssued, options)).toBe(false);
});
});
});

describe("verify", () => {
it("should verify a document with dns binding to did", async () => {
const fragment = await openAttestationDnsDidIdentityProof.verify(documentDnsDidSigned, options);
expect(fragment).toMatchInlineSnapshot(`
Object {
"data": Array [
Object {
"key": "did:ethr:0xE712878f6E8d5d4F9e87E10DA604F9cB564C9a89#controller",
"location": "example.tradetrust.io",
"status": "VALID",
},
],
"name": "OpenAttestationDnsDidIdentityProof",
"status": "VALID",
"type": "ISSUER_IDENTITY",
}
`);
});

it("should verify a document without dns binding to did", async () => {
const fragment = await openAttestationDnsDidIdentityProof.verify(documentDnsDidNoDnsTxt, options);
expect(fragment).toMatchInlineSnapshot(`
Object {
"data": Array [
Object {
"key": "did:ethr:0xE712878f6E8d5d4F9e87E10DA604F9cB564C9a89#controller",
"location": "example.com",
"status": "INVALID",
describe("v2", () => {
it("should verify a document with dns binding to did", async () => {
const fragment = await openAttestationDnsDidIdentityProof.verify(documentDnsDidSigned, options);
expect(fragment).toMatchInlineSnapshot(`
Object {
"data": Array [
Object {
"key": "did:ethr:0xE712878f6E8d5d4F9e87E10DA604F9cB564C9a89#controller",
"location": "example.tradetrust.io",
"status": "VALID",
},
],
"name": "OpenAttestationDnsDidIdentityProof",
"status": "VALID",
"type": "ISSUER_IDENTITY",
}
`);
});
it("should verify a document without dns binding to did", async () => {
const fragment = await openAttestationDnsDidIdentityProof.verify(documentDnsDidNoDnsTxt, options);
expect(fragment).toMatchInlineSnapshot(`
Object {
"data": Array [
Object {
"key": "did:ethr:0xE712878f6E8d5d4F9e87E10DA604F9cB564C9a89#controller",
"location": "example.com",
"status": "INVALID",
},
],
"name": "OpenAttestationDnsDidIdentityProof",
"status": "INVALID",
"type": "ISSUER_IDENTITY",
}
`);
});
it("should error if document has issuers not using DNS-DID", async () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only test that changed, right now returning only error since the entire document isnt valid anyway (not suppose to mix)

const fragment = await openAttestationDnsDidIdentityProof.verify(documentDnsDidMixedTokenRegistryValid, options);
expect(fragment).toMatchInlineSnapshot(`
Object {
"data": [Error: Issuer is not using DID-DNS identityProof type],
"name": "OpenAttestationDnsDidIdentityProof",
"reason": Object {
"code": 3,
"codeString": "INVALID_ISSUERS",
"message": "Issuer is not using DID-DNS identityProof type",
},
],
"name": "OpenAttestationDnsDidIdentityProof",
"status": "INVALID",
"type": "ISSUER_IDENTITY",
}
`);
"status": "ERROR",
"type": "ISSUER_IDENTITY",
}
`);
});
});

it("should fail if document has issuers not using DNS-DID", async () => {
const validFragment = await openAttestationDnsDidIdentityProof.verify(
documentDnsDidMixedTokenRegistryValid,
options
);
expect(validFragment).toMatchInlineSnapshot(`
Object {
"data": Array [
Object {
describe("v3", () => {
it("should return valid fragment for document with dns binding to did", async () => {
const fragment = await openAttestationDnsDidIdentityProof.verify(v3DnsDidSigned, options);
expect(fragment).toMatchInlineSnapshot(`
Object {
"data": Object {
"key": "did:ethr:0xE712878f6E8d5d4F9e87E10DA604F9cB564C9a89#controller",
"location": "example.tradetrust.io",
"status": "VALID",
},
Object {
"reason": Object {
"code": 3,
"codeString": "INVALID_ISSUERS",
"message": "Issuer is not using DID-DNS identityProof type",
},
"status": "INVALID",
"name": "OpenAttestationDnsDidIdentityProof",
"status": "VALID",
"type": "ISSUER_IDENTITY",
}
`);
});
it("should return valid fragment for document without dns binding to did", async () => {
yehjxraymond marked this conversation as resolved.
Show resolved Hide resolved
const documentWithoutDnsBinding = {
...v3DnsDidSigned,
openAttestationMetadata: {
...v3DnsDidSigned.openAttestationMetadata,
identityProof: {
type: v3.IdentityProofType.DNSDid,
identifier: "example.com",
},
],
"name": "OpenAttestationDnsDidIdentityProof",
"status": "INVALID",
"type": "ISSUER_IDENTITY",
}
`);

const invalidFragment = await openAttestationDnsDidIdentityProof.verify(
documentDnsDidMixedTokenRegistryInvalid,
options
);
expect(invalidFragment).toMatchInlineSnapshot(`
Object {
"data": Array [
Object {
},
};
const fragment = await openAttestationDnsDidIdentityProof.verify(documentWithoutDnsBinding, options);
expect(fragment).toMatchInlineSnapshot(`
Object {
"data": Object {
"key": "did:ethr:0xE712878f6E8d5d4F9e87E10DA604F9cB564C9a89#controller",
"location": "example.com",
"status": "INVALID",
},
Object {
"reason": Object {
"code": 3,
"codeString": "INVALID_ISSUERS",
"message": "Issuer is not using DID-DNS identityProof type",
},
"status": "INVALID",
},
],
"name": "OpenAttestationDnsDidIdentityProof",
"status": "INVALID",
"type": "ISSUER_IDENTITY",
}
`);
"name": "OpenAttestationDnsDidIdentityProof",
"status": "INVALID",
"type": "ISSUER_IDENTITY",
}
`);
});
});
});
Loading