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

Update ZKP tests for changes in VC Data Model v1.1 #127

Open
wants to merge 1 commit into
base: gh-pages
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions implementations/generate.js
Expand Up @@ -46,8 +46,19 @@ const deprecatedTests = [
'Basic Documents Presentations MUST include `verifiableCredential` and `proof`',
'Basic Documents Presentations MUST include `verifiableCredential` and `proof` (negative - missing `verifiableCredential`)',
'Basic Documents Presentations MUST include `verifiableCredential` and `proof` (negative - missing `proof`)',
'Zero-Knowledge Proofs (optional) A verifiable credential... MUST contain a credentialSchema',
'Zero-Knowledge Proofs (optional) A verifiable credential... MUST contain a credentialSchema (negative - credentialSchema missing)',
'Zero-Knowledge Proofs (optional) A verifiable credential... Each credentialSchema... MUST specify a type',
'Zero-Knowledge Proofs (optional) A verifiable credential... Each credentialSchema... MUST specify a type (negative - type missing)',
'Zero-Knowledge Proofs (optional) A verifiable credential... Each credentialSchema... MUST specify an `id` property',
'Zero-Knowledge Proofs (optional) A verifiable credential... Each credentialSchema... MUST specify an `id` property (negative - `id` missing)',
'Zero-Knowledge Proofs (optional) A verifiable credential... Each credentialSchema... value of `id` MUST be a URI identifying a schema file',
'Zero-Knowledge Proofs (optional) A verifiable presentation... MUST include `verifiableCredential`',
'Zero-Knowledge Proofs (optional) A verifiable presentation... MUST include `verifiableCredential` (negative - missing `verifiableCredential`)',
'Zero-Knowledge Proofs (optional) A verifiable presentation... MUST include `proof`',
'Zero-Knowledge Proofs (optional) A verifiable presentation... MUST include `proof` (negative - missing `proof`)',
'Zero-Knowledge Proofs (optional) A verifiable presentation... Each verifiable credential... MUST have a `credentialSchema` member',
'Zero-Knowledge Proofs (optional) A verifiable presentation... Each verifiable credential... MUST contain a credentialSchema (negative - credentialSchema missing)'
];

const invalidTests = [
Expand Down
87 changes: 10 additions & 77 deletions test/vc-data-model-1.0/60-zkp.js
Expand Up @@ -27,63 +27,13 @@ describe('Zero-Knowledge Proofs (optional)', function() {
});

describe('A verifiable credential...', function() {
it('MUST contain a credentialSchema', async function() {
const doc = await util.generate('example-015-zkp.jsonld', generatorOptions);
const isArray = Array.isArray(doc.credentialSchema) &&
doc.credentialSchema.length > 0;
const isObject = doc.credentialSchema && typeof doc.credentialSchema.id === 'string';
expect(isArray || isObject).to.be.true;
});
it('MUST contain a credentialSchema (negative - credentialSchema missing)', async function() {
await expect(util.generate(
'example-015-zkp-bad-no-credential-schema.jsonld', generatorOptions))
.to.be.rejectedWith(Error);
it.skip('derived verifiable credential MUST contain all information necessary to verify', async function() {
/*Each derived verifiable credential within a verifiable presentation MUST
contain all information necessary to verify the verifiable credential,
either by including it directly within the credential, or by referencing
the necessary information.*/
});
describe('Each credentialSchema...', function() {
it('MUST specify a type', async function() {
const doc = await util.generate('example-015-zkp-credential-schema-array.jsonld',
generatorOptions);
should.exist(doc.credentialSchema);
let schemas = [].concat(doc.credentialSchema);
expect(schemas.length > 0).to.be.true;

for(let schema of schemas) {
schema.type.should.be.a('string');
}
});
it('MUST specify a type (negative - type missing)', async function() {
await expect(util.generate(
'example-015-zkp-bad-no-credential-schema-type.jsonld', generatorOptions))
.to.be.rejectedWith(Error);
});
it('MUST specify an `id` property', async function() {
// test for `id` property existence
const doc = await util.generate('example-015-zkp.jsonld', generatorOptions);
should.exist(doc.credentialSchema.id);
let schemas = [].concat(doc.credentialSchema);
expect(schemas.length > 0).to.be.true;

for(let schema of schemas) {
schema.id.should.be.a('string');
}
});
it('MUST specify an `id` property (negative - `id` missing)', async function() {
await expect(util.generate(
'example-015-zkp-bad-no-credential-schema-id.jsonld', generatorOptions))
.to.be.rejectedWith(Error);
});

it('value of `id` MUST be a URI identifying a schema file', async function() {
// test that `id`'s value is a valid URI
// TODO: https://github.com/w3c/vc-data-model/issues/381
const doc = await util.generate('example-015-zkp.jsonld', generatorOptions);
const schemas = [].concat(doc.credentialSchema);

for(let schema of schemas) {
expect(schema.id).to.match(uriRegex);
}
});
});
// all verifiable credentials need to have a proof,
// so these tests feel redundant
it('MUST contain a proof', async function() {
Expand Down Expand Up @@ -128,28 +78,11 @@ describe('Zero-Knowledge Proofs (optional)', function() {
expect(hasType(doc, 'VerifiablePresentation')).to.be.true;
});

describe('Each verifiable credential...', function() {
it('MUST have a `credentialSchema` member', async function() {
const doc = await util.generatePresentation('example-015-zkp-vp.jsonld', generatorOptions);
if (Array.isArray(doc.verifiableCredential)) {
let creds = [].concat(doc.verifiableCredential)
for(let cred of creds){
const isArray = Array.isArray(cred.credentialSchema) && cred.credentialSchema.length > 0;
const isObject = cred.credentialSchema && typeof cred.credentialSchema.id === 'string';
expect(isArray || isObject).to.be.true;
}
} else {
// only one credential
const isArray = Array.isArray(doc.verifiableCredential.credentialSchema) && doc.verifiableCredential.credentialSchema.length > 0;
const isObject = doc.verifiableCredential.credentialSchema && typeof doc.verifiableCredential.credentialSchema.id === 'string';
expect(isArray || isObject).to.be.true;
}
});
it('MUST contain a credentialSchema (negative - credentialSchema missing)', async function() {
await expect(util.generate(
'example-015-zkp-vp-bad-no-credential-schema.jsonld', generatorOptions))
.to.be.rejectedWith(Error);
});
it.skip('credential definition MUST be defined in credentialSchema', async function() {
/*If a credential definition is being used, the credential
definition MUST be defined in the credentialSchema property,
so that it can be used by all parties to perform various cryptographic
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
so that it can be used by all parties to perform various cryptographic
so all parties can use it to perform various cryptographic

Copy link
Member

Choose a reason for hiding this comment

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

@clehner -- If #127 (comment) is asking me about the above rephrasing, then I would definitely change it here, and if such editorial change can still be made in the other doc, then I would change it there as well.

operations in zero-knowledge.*/
});

it.skip('MUST NOT leak information', async function() {
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.