Skip to content

Commit c20af05

Browse files
committed
Handle implemented & multi-key-types.
1 parent df7e572 commit c20af05

File tree

4 files changed

+163
-153
lines changed

4 files changed

+163
-153
lines changed

tests/70-conformance.js

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,14 @@ for(const suiteName of cryptosuites) {
2323
mandatoryPointers,
2424
selectivePointers
2525
} = credentials.create[vcVersion];
26-
for(const keyType of vectors.keyTypes) {
27-
conformanceSuite({
28-
verifiers,
29-
suiteName,
30-
keyType,
31-
vcVersion,
32-
credential: document,
33-
mandatoryPointers,
34-
selectivePointers
35-
});
36-
}
26+
conformanceSuite({
27+
verifiers,
28+
suiteName,
29+
keyTypes: vectors.keyTypes,
30+
vcVersion,
31+
credential: document,
32+
mandatoryPointers,
33+
selectivePointers
34+
});
3735
}
3836
}

tests/80-data-model.js

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,14 @@ for(const suiteName of cryptosuites) {
2424
mandatoryPointers,
2525
selectivePointers
2626
} = credentials.create[vcVersion];
27-
for(const keyType of vectors.keyTypes) {
28-
dataModelSuite({
29-
issuers,
30-
suiteName,
31-
keyType,
32-
vcVersion,
33-
credential: document,
34-
mandatoryPointers,
35-
selectivePointers
36-
});
37-
}
27+
dataModelSuite({
28+
issuers,
29+
suiteName,
30+
keyTypes: vectors.keyTypes,
31+
vcVersion,
32+
credential: document,
33+
mandatoryPointers,
34+
selectivePointers
35+
});
3836
}
3937
}

tests/suites/conformance.js

Lines changed: 46 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {getSuite} from '../vc-generator/cryptosuites.js';
1414
export function conformanceSuite({
1515
verifiers,
1616
suiteName,
17-
keyType,
17+
keyTypes,
1818
vcVersion,
1919
credential,
2020
mandatoryPointers,
@@ -24,52 +24,58 @@ export function conformanceSuite({
2424
return describe(`${suiteName} - Conformance - VC ${vcVersion}`, function() {
2525
this.matrix = true;
2626
this.report = true;
27-
this.implemented = [...verifiers];
27+
this.implemented = [];
2828
this.rowLabel = 'Test Name';
2929
this.columnLabel = 'Implementation';
30-
let credentials = new Map();
30+
const credentials = new Map(keyTypes.map(kt => [kt, null]));
3131
before(async function() {
32-
credentials = await setup({
33-
credential,
34-
mandatoryPointers,
35-
selectivePointers,
36-
suiteName,
37-
keyType
38-
});
32+
for(const keyType of keyTypes) {
33+
credentials.set(keyType, await setup({
34+
credential,
35+
mandatoryPointers,
36+
selectivePointers,
37+
suiteName,
38+
keyType
39+
}));
40+
}
3941
});
4042
for(const [name, {endpoints}] of verifiers) {
4143
const [verifier] = endpoints;
42-
describe(`${name}: ${keyType}`, function() {
43-
beforeEach(function() {
44-
this.currentTest.cell = {
45-
rowId: this.currentTest.title,
46-
columnId: this.currentTest.parent.title
47-
};
48-
});
49-
it('Specifically, all relevant normative statements in Sections 2. ' +
50-
'Data Model and 3. Algorithms of this document MUST be enforced.',
51-
async function() {
52-
this.test.link = 'https://w3c.github.io/vc-di-ecdsa/#:~:text=Specifically%2C%20all%20relevant%20normative%20statements%20in%20Sections%202.%20Data%20Model%20and%203.%20Algorithms%20of%20this%20document%20MUST%20be%20enforced.';
53-
for(const [key, credential] of credentials) {
54-
await assertions.verificationFail({
55-
verifier,
56-
credential,
57-
reason: `Should not verify VC with ${key}`
58-
});
59-
}
60-
});
61-
it('Conforming processors MUST produce errors when non-conforming ' +
62-
'documents are consumed.', async function() {
63-
this.test.link = 'https://w3c.github.io/vc-di-ecdsa/#:~:text=Conforming%20processors%20MUST%20produce%20errors%20when%20non%2Dconforming%20documents%20are%20consumed.';
64-
for(const [key, credential] of credentials) {
65-
await assertions.verificationFail({
66-
verifier,
67-
credential,
68-
reason: `Should not verify VC with ${key}`
69-
});
70-
}
44+
for(const keyType of keyTypes) {
45+
// add implementer name and keyType to test report
46+
this.implemented.push(`${name}: ${keyType}`);
47+
describe(`${name}: ${keyType}`, function() {
48+
beforeEach(function() {
49+
this.currentTest.cell = {
50+
rowId: this.currentTest.title,
51+
columnId: this.currentTest.parent.title
52+
};
53+
});
54+
it('Specifically, all relevant normative statements in Sections 2. ' +
55+
'Data Model and 3. Algorithms of this document MUST be enforced.',
56+
async function() {
57+
this.test.link = 'https://w3c.github.io/vc-di-ecdsa/#:~:text=Specifically%2C%20all%20relevant%20normative%20statements%20in%20Sections%202.%20Data%20Model%20and%203.%20Algorithms%20of%20this%20document%20MUST%20be%20enforced.';
58+
for(const [key, credential] of credentials.get(keyType)) {
59+
await assertions.verificationFail({
60+
verifier,
61+
credential,
62+
reason: `Should not verify VC with ${key}`
63+
});
64+
}
65+
});
66+
it('Conforming processors MUST produce errors when non-conforming ' +
67+
'documents are consumed.', async function() {
68+
this.test.link = 'https://w3c.github.io/vc-di-ecdsa/#:~:text=Conforming%20processors%20MUST%20produce%20errors%20when%20non%2Dconforming%20documents%20are%20consumed.';
69+
for(const [key, credential] of credentials.get(keyType)) {
70+
await assertions.verificationFail({
71+
verifier,
72+
credential,
73+
reason: `Should not verify VC with ${key}`
74+
});
75+
}
76+
});
7177
});
72-
});
78+
}
7379
}
7480
});
7581
}

tests/suites/data-model.js

Lines changed: 99 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -12,111 +12,119 @@ import {expect} from 'chai';
1212
export function dataModelSuite({
1313
issuers,
1414
suiteName,
15-
keyType,
15+
keyTypes,
1616
vcVersion,
1717
credential,
1818
mandatoryPointers
1919
}) {
2020
return describe(`${suiteName} - Data Model - VC ${vcVersion}`, function() {
2121
this.matrix = true;
2222
this.report = true;
23-
this.implemented = [...issuers];
23+
this.implemented = [];
2424
this.rowLabel = 'Test Name';
2525
this.columnLabel = 'Implementation';
2626
for(const [name, {endpoints}] of issuers) {
27-
const [issuer] = endpoints;
28-
// does the endpoint support this test?
29-
if(!endpointCheck({endpoint: issuer, keyType, vcVersion})) {
30-
continue;
31-
}
32-
describe(`${name}: ${keyType}`, function() {
33-
let securedCredential = null;
34-
let proofs = [];
35-
before(async function() {
36-
securedCredential = await createInitialVc({
37-
issuer,
38-
vcVersion,
39-
vc: credential,
40-
mandatoryPointers
41-
});
42-
if(securedCredential) {
43-
proofs = Array.isArray(securedCredential.proof) ?
44-
securedCredential?.proof : [securedCredential?.proof];
45-
// only test proofs that match the relevant cryptosuite
46-
proofs = proofs.filter(p => p?.cryptosuite === suiteName);
27+
for(const keyType of keyTypes) {
28+
for(const issuer of endpoints) {
29+
// does the endpoint support this test?
30+
if(!endpointCheck({endpoint: issuer, keyType, vcVersion})) {
31+
continue;
4732
}
48-
});
49-
beforeEach(function() {
50-
this.currentTest.cell = {
51-
rowId: this.currentTest.title,
52-
columnId: this.currentTest.parent.title
53-
};
54-
});
55-
function assertBefore() {
56-
expect(
57-
securedCredential,
58-
`Expected issuer ${name}: ${keyType} to issue a VC.`
59-
).to.exist;
60-
expect(
61-
securedCredential,
62-
'Expected VC to be an object.'
63-
).to.be.an('object');
64-
}
65-
it('The publicKeyMultibase value of the verification method MUST ' +
66-
'start with the base-58-btc prefix (z), as defined in the ' +
67-
'Multibase section of Controller Documents 1.0. ',
68-
async function() {
69-
this.test.link = 'https://w3c.github.io/vc-di-ecdsa/#data-model:~:text=The%20publicKeyMultibase%20value%20of%20the%20verification%20method%20MUST%20start%20with%20the%20base%2D58%2Dbtc%20prefix%20(z)%2C%20as%20defined%20in%20the%20Multibase%20section%20of%20Controller%20Documents%201.0.';
70-
assertBefore();
71-
for(const proof of proofs) {
72-
expect(proof.verificationMethod).to.exist;
73-
expect(proof.verificationMethod).to.be.a('string');
74-
const didDoc = await didResolver({url: proof.verificationMethod});
75-
expect(didDoc).to.be.an('object');
76-
expect(didDoc.publicKeyMultibase).to.be.a('string');
77-
expect(
78-
assertions.shouldBeBs58(didDoc.publicKeyMultibase),
79-
'Expected "publicKeyMultibase" to be Base58 encoded.'
80-
).to.be.true;
81-
}
82-
});
83-
it('Any other encoding MUST NOT be allowed. (verificationMethod)',
84-
async function() {
85-
this.test.link = 'https://w3c.github.io/vc-di-ecdsa/#multikey';
86-
assertBefore();
87-
for(const proof of proofs) {
88-
expect(proof.verificationMethod).to.exist;
89-
expect(proof.verificationMethod).to.be.a('string');
90-
const didDoc = await didResolver({url: proof.verificationMethod});
91-
expect(didDoc).to.be.an('object');
92-
expect(didDoc.publicKeyMultibase).to.be.a('string');
33+
// add implementer name and keyType to test report
34+
this.implemented.push(`${name}: ${keyType}`);
35+
describe(`${name}: ${keyType}`, function() {
36+
let securedCredential = null;
37+
let proofs = [];
38+
before(async function() {
39+
securedCredential = await createInitialVc({
40+
issuer,
41+
vcVersion,
42+
vc: credential,
43+
mandatoryPointers
44+
});
45+
if(securedCredential) {
46+
proofs = Array.isArray(securedCredential.proof) ?
47+
securedCredential?.proof : [securedCredential?.proof];
48+
// only test proofs that match the relevant cryptosuite
49+
proofs = proofs.filter(p => p?.cryptosuite === suiteName);
50+
}
51+
});
52+
beforeEach(function() {
53+
this.currentTest.cell = {
54+
rowId: this.currentTest.title,
55+
columnId: this.currentTest.parent.title
56+
};
57+
});
58+
function assertBefore() {
59+
expect(
60+
securedCredential,
61+
`Expected issuer ${name}: ${keyType} to issue a VC.`
62+
).to.exist;
9363
expect(
94-
assertions.shouldBeBs58(didDoc.publicKeyMultibase),
95-
'Expected "publicKeyMultibase" to be Base58 encoded.'
96-
).to.be.true;
64+
securedCredential,
65+
'Expected VC to be an object.'
66+
).to.be.an('object');
9767
}
68+
it('The publicKeyMultibase value of the verification method MUST ' +
69+
'start with the base-58-btc prefix (z), as defined in the ' +
70+
'Multibase section of Controller Documents 1.0. ',
71+
async function() {
72+
this.test.link = 'https://w3c.github.io/vc-di-ecdsa/#data-model:~:text=The%20publicKeyMultibase%20value%20of%20the%20verification%20method%20MUST%20start%20with%20the%20base%2D58%2Dbtc%20prefix%20(z)%2C%20as%20defined%20in%20the%20Multibase%20section%20of%20Controller%20Documents%201.0.';
73+
assertBefore();
74+
for(const proof of proofs) {
75+
expect(proof.verificationMethod).to.exist;
76+
expect(proof.verificationMethod).to.be.a('string');
77+
const didDoc = await didResolver({
78+
url: proof.verificationMethod});
79+
expect(didDoc).to.be.an('object');
80+
expect(didDoc.publicKeyMultibase).to.be.a('string');
81+
expect(
82+
assertions.shouldBeBs58(didDoc.publicKeyMultibase),
83+
'Expected "publicKeyMultibase" to be Base58 encoded.'
84+
).to.be.true;
85+
}
86+
});
87+
it('Any other encoding MUST NOT be allowed. (verificationMethod)',
88+
async function() {
89+
this.test.link = 'https://w3c.github.io/vc-di-ecdsa/#multikey';
90+
assertBefore();
91+
for(const proof of proofs) {
92+
expect(proof.verificationMethod).to.exist;
93+
expect(proof.verificationMethod).to.be.a('string');
94+
const didDoc = await didResolver({
95+
url: proof.verificationMethod});
96+
expect(didDoc).to.be.an('object');
97+
expect(didDoc.publicKeyMultibase).to.be.a('string');
98+
expect(
99+
assertions.shouldBeBs58(didDoc.publicKeyMultibase),
100+
'Expected "publicKeyMultibase" to be Base58 encoded.'
101+
).to.be.true;
102+
}
103+
});
104+
it('The type property MUST be DataIntegrityProof.',
105+
async function() {
106+
this.test.link = 'https://w3c.github.io/vc-di-ecdsa/#multikey:~:text=The%20type%20property%20MUST%20be%20DataIntegrityProof.';
107+
assertBefore();
108+
for(const proof of proofs) {
109+
expect(proof.type).to.exist;
110+
expect(proof.type).to.be.a('string');
111+
expect(proof.type).to.equal('DataIntegrityProof');
112+
}
113+
});
114+
it('The cryptosuite property MUST be ecdsa-rdfc-2019, ' +
115+
'ecdsa-jcs-2019, or ecdsa-sd-2023.', async function() {
116+
this.test.link = 'https://w3c.github.io/vc-di-ecdsa/#multikey:~:text=The%20cryptosuite%20property%20MUST%20be%20ecdsa%2Drdfc%2D2019%2C%20ecdsa%2Djcs%2D2019%2C%20or%20ecdsa%2Dsd%2D2023.';
117+
assertBefore();
118+
for(const proof of proofs) {
119+
expect(proof.cryptosuite).to.exist;
120+
expect(proof.cryptosuite).to.be.a('string');
121+
expect(proof.cryptosuite).to.be.oneOf(
122+
['ecdsa-rdfc-2019', 'edcsa-jcs-2019', 'ecdsa-sd-2023']);
123+
}
124+
});
98125
});
99-
it('The type property MUST be DataIntegrityProof.', async function() {
100-
this.test.link = 'https://w3c.github.io/vc-di-ecdsa/#multikey:~:text=The%20type%20property%20MUST%20be%20DataIntegrityProof.';
101-
assertBefore();
102-
for(const proof of proofs) {
103-
expect(proof.type).to.exist;
104-
expect(proof.type).to.be.a('string');
105-
expect(proof.type).to.equal('DataIntegrityProof');
106-
}
107-
});
108-
it('The cryptosuite property MUST be ecdsa-rdfc-2019, ' +
109-
'ecdsa-jcs-2019, or ecdsa-sd-2023.', async function() {
110-
this.test.link = 'https://w3c.github.io/vc-di-ecdsa/#multikey:~:text=The%20cryptosuite%20property%20MUST%20be%20ecdsa%2Drdfc%2D2019%2C%20ecdsa%2Djcs%2D2019%2C%20or%20ecdsa%2Dsd%2D2023.';
111-
assertBefore();
112-
for(const proof of proofs) {
113-
expect(proof.cryptosuite).to.exist;
114-
expect(proof.cryptosuite).to.be.a('string');
115-
expect(proof.cryptosuite).to.be.oneOf(
116-
['ecdsa-rdfc-2019', 'edcsa-jcs-2019', 'ecdsa-sd-2023']);
117-
}
118-
});
119-
});
126+
}
127+
}
120128
}
121129
});
122130
}

0 commit comments

Comments
 (0)