Skip to content

Commit

Permalink
presentation holder
Browse files Browse the repository at this point in the history
  • Loading branch information
ipbyrne committed Feb 7, 2024
1 parent 602c763 commit ec2883a
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 1 deletion.
16 changes: 16 additions & 0 deletions src/cr1/validator/w3c.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,21 @@ const issuer = (result: ValidationResult, pointer: string, value: any) => {
}
}

// https://www.w3.org/TR/vc-data-model-2.0/#presentations-0
const holder = (result: ValidationResult, pointer: string, value: any) => {
if (pointer.endsWith('/holder') || pointer.endsWith('/holder/id')) {
const issuerAllowed = stringIsAValidUrl(value, allowedProtocols)
if (!issuerAllowed) {
result.warnings.push({
// eslint-disable-next-line @typescript-eslint/no-explicit-any
message: `Holder MUST be a valid URL or an object containing an id property that is a valid URL`,
pointer,
reference: 'https://www.w3.org/TR/vc-data-model-2.0/#presentations-0'
})
}
}
}

// https://www.w3.org/TR/2024/CRD-vc-data-model-2.0-20240205/#types
const types = (result: ValidationResult, pointer: string, value: any) => {
// I'm not writing a test for:
Expand Down Expand Up @@ -114,6 +129,7 @@ export const conformance = (result: ValidationResult) => {
types(result, pointer, value)
names_and_descriptions(result, pointer, value)
issuer(result, pointer, value)
holder(result, pointer, value)
}

return result
Expand Down
70 changes: 69 additions & 1 deletion test/w3c-cr-1/5-data-model.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,75 @@ credentialSubject:

// https://www.w3.org/TR/2024/CRD-vc-data-model-2.0-20240205/#presentations-0
describe("Presentations", () => {
it.todo("complete me")
describe("Presentation - verifiableCredential", () => {
it.todo("complete me")
});
describe("Presentation - holder", () => {
it("can be object with id as url", async () => {
const validation = await review(
text(`
"@context":
- https://www.w3.org/ns/credentials/v2
type:
- VerifiablePresentation
holder:
id: https://university.example/issuers/565049
`)
);
expect(validation.warnings).toEqual([]);
})

it("can be url", async () => {
const validation = await review(
text(`
"@context":
- https://www.w3.org/ns/credentials/v2
type:
- VerifiablePresentation
holder: https://university.example/issuers/565049
`)
);
expect(validation.warnings).toEqual([]);
})

it("gives warning if issuer not valid url", async () => {
const validation = await review(
text(`
"@context":
- https://www.w3.org/ns/credentials/v2
type:
- VerifiablePresentation
holder: test
`)
);
expect(validation.warnings[0]).toStrictEqual({
// eslint-disable-next-line @typescript-eslint/no-explicit-any
message: `Holder MUST be a valid URL or an object containing an id property that is a valid URL`,
pointer: '/holder',
reference: 'https://www.w3.org/TR/vc-data-model-2.0/#presentations-0'
});
})

it("gives warning if issuer.id not valid url", async () => {
const validation = await review(
text(`
"@context":
- https://www.w3.org/ns/credentials/v2
type:
- VerifiablePresentation
holder:
id: test
`)
);
expect(validation.warnings[1]).toStrictEqual({
// eslint-disable-next-line @typescript-eslint/no-explicit-any
message: `Holder MUST be a valid URL or an object containing an id property that is a valid URL`,
pointer: '/holder/id',
reference: 'https://www.w3.org/TR/vc-data-model-2.0/#presentations-0'
});
})
});

});

// it.todo('data model tests')
Expand Down

0 comments on commit ec2883a

Please sign in to comment.