Skip to content

Commit

Permalink
fix: v3 cred needs OpenAttestationCredential type
Browse files Browse the repository at this point in the history
  • Loading branch information
Nebulis committed Jun 28, 2021
1 parent ad617d1 commit 5c842bf
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 63 deletions.
5 changes: 3 additions & 2 deletions src/3.0/__tests__/e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import sampleDid from "../schema/sample-credential-did.json";

const openAttestationDataWithDid = sampleDid as OpenAttestationDocument;

const openAttestationData: OpenAttestationDocument = {
const openAttestationData = {
"@context": [
"https://www.w3.org/2018/credentials/v1",
"https://www.w3.org/2018/credentials/examples/v1",
Expand All @@ -30,7 +30,7 @@ const openAttestationData: OpenAttestationDocument = {
validFrom: "2010-01-01T19:23:24Z",
issuanceDate: "2010-01-01T19:23:24Z",
name: "document owner name",
type: ["VerifiableCredential", "UniversityDegreeCredential"],
type: ["VerifiableCredential", "UniversityDegreeCredential", "OpenAttestationCredential"],
credentialSubject: {
id: "did:example:ebfeb1f712ebc6f1c276e12ec21",
degree: {
Expand All @@ -56,6 +56,7 @@ const openAttestationData: OpenAttestationDocument = {
},
issuer: {
id: "http://some.example.com",
type: "OpenAttestationIssuer",
name: "DEMO STORE",
},
};
Expand Down
3 changes: 2 additions & 1 deletion src/3.0/schema/sample-credential-did.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
"validFrom": "2010-01-01T19:23:24Z",
"issuer": {
"id": "https://example.com",
"type": "OpenAttestationIssuer",
"name": "DEMO STORE"
},
"type": ["VerifiableCredential", "DrivingLicenceCredential"],
"type": ["VerifiableCredential", "DrivingLicenceCredential", "OpenAttestationCredential"],
"credentialSubject": {
"id": "did:example:SERIAL_NUMBER_123",
"class": [
Expand Down
3 changes: 2 additions & 1 deletion src/3.0/schema/sample-credential-document-store.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@
"https://schemata.openattestation.com/com/openattestation/1.0/OpenAttestation.v3.json",
"https://schemata.openattestation.com/com/openattestation/1.0/CustomContext.json"
],
"type": ["VerifiableCredential", "DrivingLicenceCredential", "OpenAttestationCredential"],
"reference": "SERIAL_NUMBER_123",
"name": "Republic of Singapore Driving Licence",
"issuanceDate": "2010-01-01T19:23:24Z",
"validFrom": "2010-01-01T19:23:24Z",
"issuer": {
"id": "https://example.com",
"type": "OpenAttestationIssuer",
"name": "DEMO STORE"
},
"type": ["VerifiableCredential", "DrivingLicenceCredential"],
"credentialSubject": {
"id": "did:example:SERIAL_NUMBER_123",
"class": [
Expand Down
2 changes: 1 addition & 1 deletion src/3.0/schema/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
}
},
"required": ["id", "name"],
"additionalProperties": false
"additionalProperties": true
}
},
"properties": {
Expand Down
33 changes: 0 additions & 33 deletions src/3.0/schema/schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -506,39 +506,6 @@ describe("schema/3.0", () => {
const wrappedDocument = await wrapDocument(document, { externalSchemaId: $id, version: SchemaId.v3 });
expect(wrappedDocument.version).toStrictEqual(SchemaId.v3);
});
it("should be invalid when adding additional data", async () => {
expect.assertions(2);

const document = { ...cloneDeep(sampleDoc), issuer: { ...sample.issuer, key: "any" } };
try {
await wrapDocument(document, { externalSchemaId: $id, version: SchemaId.v3 });
} catch (e) {
expect(e).toHaveProperty("message", "Invalid document");
expect(e).toHaveProperty("validationErrors", [
{
keyword: "additionalProperties",
instancePath: "/issuer",
schemaPath: "#/definitions/issuer/additionalProperties",
params: { additionalProperty: "key" },
message: "must NOT have additional properties",
},
{
keyword: "type",
instancePath: "/issuer",
schemaPath: "#/properties/issuer/oneOf/1/type",
params: { type: "string" },
message: "must be string",
},
{
keyword: "oneOf",
instancePath: "/issuer",
schemaPath: "#/properties/issuer/oneOf",
params: { passingSchemas: null },
message: "must match exactly one schema in oneOf",
},
]);
}
});
it("should be invalid when id is not a URI", async () => {
expect.assertions(2);

Expand Down
6 changes: 5 additions & 1 deletion src/3.0/validate/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,11 @@ export async function validateW3C<T extends OpenAttestationDocument>(credential:
await expand(credential, {
expansionMap: (info) => {
if (info.unmappedProperty) {
throw new Error("The property '" + info.unmappedProperty + "' in the input was not defined in the context");
throw new Error(
`"The property ${info.activeProperty ? `${info.activeProperty}.` : ""}${
info.unmappedProperty
} in the input was not defined in the context"`
);
}
},
documentLoader,
Expand Down
13 changes: 7 additions & 6 deletions src/shared/utils/__tests__/diagnose.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@ describe("diagnose", () => {
],
issuer: {
name: "name",
type: "OpenAttestationIssuer",
id: "https://example.com",
},
issuanceDate: "2010-01-01T19:23:24Z",
type: ["VerifiableCredential", "UniversityDegreeCredential"],
type: ["VerifiableCredential", "UniversityDegreeCredential", "OpenAttestationCredential"],
credentialSubject: {
id: "did:example:ebfeb1f712ebc6f1c276e12ec21",
degree: {
Expand All @@ -53,18 +54,18 @@ describe("diagnose", () => {
type: v3.ProofType.OpenAttestationProofMethod,
method: v3.Method.DocumentStore,
},
template: {
url: "https://",
name: "",
type: v3.TemplateType.EmbeddedRenderer,
},
identityProof: {
identifier: "whatever",
type: v2.IdentityProofType.DNSTxt,
},
},
name: "",
reference: "",
template: {
url: "https://",
name: "",
type: v3.TemplateType.EmbeddedRenderer,
},
validFrom: "2010-01-01T19:23:24Z",
},
{ version: SchemaId.v3 }
Expand Down
12 changes: 6 additions & 6 deletions src/shared/utils/__tests__/guard.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe("guard", () => {
id: "https://example.com",
},
issuanceDate: "2010-01-01T19:23:24Z",
type: ["VerifiableCredential", "UniversityDegreeCredential"],
type: ["VerifiableCredential", "UniversityDegreeCredential", "OpenAttestationCredential"],
credentialSubject: {
id: "did:example:ebfeb1f712ebc6f1c276e12ec21",
degree: {
Expand All @@ -63,14 +63,14 @@ describe("guard", () => {
identifier: "whatever",
type: v2.IdentityProofType.DNSTxt,
},
template: {
url: "https://",
name: "",
type: v3.TemplateType.EmbeddedRenderer,
},
},
name: "",
reference: "",
template: {
url: "https://",
name: "",
type: v3.TemplateType.EmbeddedRenderer,
},
validFrom: "2010-01-01T19:23:24Z",
},
{ version: SchemaId.v3 }
Expand Down
26 changes: 14 additions & 12 deletions src/shared/utils/__tests__/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@ describe("Util Functions", () => {
],
issuer: {
name: "name",
type: "OpenAttestationIssuer",
id: "https://example.com",
},
issuanceDate: "2010-01-01T19:23:24Z",
type: ["VerifiableCredential", "UniversityDegreeCredential"],
type: ["VerifiableCredential", "UniversityDegreeCredential", "OpenAttestationCredential"],
credentialSubject: {
id: "did:example:ebfeb1f712ebc6f1c276e12ec21",
degree: {
Expand All @@ -62,14 +63,14 @@ describe("Util Functions", () => {
identifier: "whatever",
type: v2.IdentityProofType.DNSTxt,
},
template: {
url: "https://",
name: "",
type: v3.TemplateType.EmbeddedRenderer,
},
},
name: "",
reference: "",
template: {
url: "https://",
name: "",
type: v3.TemplateType.EmbeddedRenderer,
},
validFrom: "2010-01-01T19:23:24Z",
},
{ version: SchemaId.v3 }
Expand All @@ -83,10 +84,11 @@ describe("Util Functions", () => {
],
issuer: {
name: "name",
type: "OpenAttestationIssuer",
id: "https://example.com",
},
issuanceDate: "2010-01-01T19:23:24Z",
type: ["VerifiableCredential", "UniversityDegreeCredential"],
type: ["VerifiableCredential", "UniversityDegreeCredential", "OpenAttestationCredential"],
credentialSubject: {
id: "did:example:ebfeb1f712ebc6f1c276e12ec21",
degree: {
Expand All @@ -104,14 +106,14 @@ describe("Util Functions", () => {
identifier: "whatever",
type: v2.IdentityProofType.DNSTxt,
},
template: {
url: "https://",
name: "",
type: v3.TemplateType.EmbeddedRenderer,
},
},
name: "",
reference: "",
template: {
url: "https://",
name: "",
type: v3.TemplateType.EmbeddedRenderer,
},
validFrom: "2010-01-01T19:23:24Z",
},
{ version: SchemaId.v3 }
Expand Down

0 comments on commit 5c842bf

Please sign in to comment.