Skip to content

Commit 0f1161c

Browse files
committed
Clean up the algorithms assertion.
1 parent 1ecf33e commit 0f1161c

File tree

2 files changed

+64
-62
lines changed

2 files changed

+64
-62
lines changed

index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,13 @@ export * as assertions from './assertions.js';
163163
export {generators} from './vc-generator/generators.js';
164164
export {deriveCloned, issueCloned} from './vc-generator/issuer.js';
165165
export {createDocLoader} from './vc-generator/documentLoader.js';
166+
// this is just here for backwards compatitility to avoid a major release
167+
// FIXME remove this on next MAJOR release
166168
export {
167169
dateRegex, expectedMultibasePrefix, isObjectOrArrayOfObjects,
168170
shouldBeErrorResponse, shouldBeUrl, isStringOrArrayOfStrings,
169171
isValidMultibaseEncoded, shouldBeBs58, shouldBeBase64NoPadUrl,
170172
verificationFail
171173
} from './assertions.js';
172174
export {createInitialVc} from './helpers.js';
175+
export {algorithmsAssertions} from './suites/algorithms.js';

suites/algorithms.js

Lines changed: 61 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ export function algorithmsAssertions({
88
testDescription,
99
vendorName,
1010
credential,
11+
features = {
12+
authentication: false,
13+
proofChain: false
14+
}
1115
}) {
1216
return describe(testDescription, function() {
1317
const columnId = testDescription;
@@ -54,78 +58,73 @@ and proof.proofPurpose values is not set, an error MUST be raised.',
5458
'type', 'proofPurpose', 'verificationMethod');
5559
}
5660
});
57-
it('If options has a non-null domain item, it MUST be equal to \
58-
proof.domain or an error MUST be raised.',
59-
function() {
60-
this.test.link = 'https://www.w3.org/TR/vc-data-integrity/#:~:text=If%20options%20has%20a%20non%2Dnull%20domain%20item%2C%20it%20MUST%20be%20equal%20to%20proof.domain%20or%20an%20error%20MUST%20be%20raised%20and%20SHOULD%20convey%20an%20error%20type%20of%20PROOF_GENERATION_ERROR.';
61-
this.test.cell.skipMessage = 'Pending test.';
62-
this.skip();
63-
});
64-
it('If options has a non-null challenge item, it MUST be equal to \
65-
proof.challenge or an error MUST be raised.',
66-
function() {
67-
this.test.link = 'https://www.w3.org/TR/vc-data-integrity/#:~:text=If%20options%20has%20a%20non%2Dnull%20challenge%20item%2C%20it%20MUST%20be%20equal%20to%20proof.challenge%20or%20an%20error%20MUST%20be%20raised%20and%20SHOULD%20convey%20an%20error%20type%20of%20PROOF_GENERATION_ERROR.';
68-
this.test.cell.skipMessage = 'Pending test.';
69-
this.skip();
70-
});
71-
it('Whenever this algorithm encodes strings, it MUST use UTF-8 encoding.',
61+
if(features?.authentication) {
62+
it('If options has a non-null domain item, it MUST be equal to \
63+
proof.domain or an error MUST be raised.',
7264
function() {
73-
this.test.link = 'https://www.w3.org/TR/vc-data-integrity/#:~:text=(map).-,Whenever%20this%20algorithm%20encodes%20strings%2C%20it%20MUST%20use%20UTF%2D8%20encoding.,-Let%20proof%20be';
74-
for(const proof of proofs) {
75-
expect(proof.proofValue.isWellFormed()).to.be.true;
76-
}
65+
this.test.link = 'https://www.w3.org/TR/vc-data-integrity/#:~:text=If%20options%20has%20a%20non%2Dnull%20domain%20item%2C%20it%20MUST%20be%20equal%20to%20proof.domain%20or%20an%20error%20MUST%20be%20raised%20and%20SHOULD%20convey%20an%20error%20type%20of%20PROOF_GENERATION_ERROR.';
66+
this.test.cell.skipMessage = 'Pending test.';
67+
this.skip();
7768
});
78-
it('If a proof with id equal to previousProof does not exist in allProofs, \
79-
an error MUST be raised.',
80-
function() {
81-
this.test.link = 'https://www.w3.org/TR/vc-data-integrity/#:~:text=If%20a%20proof%20with%20id%20equal%20to%20previousProofdoes%20not%20exist%20in%20allProofs%2C%20an%20error%20MUST%20be%20raised%20and%20SHOULD%20convey%20an%20error%20type%20of%20PROOF_GENERATION_ERROR.';
82-
for(const proof of proofs) {
83-
if('previousProof' in proof) {
84-
if(typeof proof.previousProof === 'string') {
85-
proofs.some(
86-
otherProof => otherProof.id == proof.previousProof).
87-
should.equal(true,
88-
'Expected previousProof ' +
89-
`${proof.previousProof} ` +
90-
'to be the id of another included proof.'
91-
);
92-
} if(Array.isArray(proof.previousProof)) {
93-
for(const previousProof in proof.previousProof) {
69+
it('If options has a non-null challenge item, it MUST be equal to \
70+
proof.challenge or an error MUST be raised.',
71+
function() {
72+
this.test.link = 'https://www.w3.org/TR/vc-data-integrity/#:~:text=If%20options%20has%20a%20non%2Dnull%20challenge%20item%2C%20it%20MUST%20be%20equal%20to%20proof.challenge%20or%20an%20error%20MUST%20be%20raised%20and%20SHOULD%20convey%20an%20error%20type%20of%20PROOF_GENERATION_ERROR.';
73+
this.test.cell.skipMessage = 'Pending test.';
74+
this.skip();
75+
});
76+
}
77+
if(features?.proofChain) {
78+
it('If a proof with id equal to previousProof does not exist in ' +
79+
'allProofs, an error MUST be raised.', function() {
80+
this.test.link = 'https://www.w3.org/TR/vc-data-integrity/#:~:text=If%20a%20proof%20with%20id%20equal%20to%20previousProofdoes%20not%20exist%20in%20allProofs%2C%20an%20error%20MUST%20be%20raised%20and%20SHOULD%20convey%20an%20error%20type%20of%20PROOF_GENERATION_ERROR.';
81+
for(const proof of proofs) {
82+
if('previousProof' in proof) {
83+
if(typeof proof.previousProof === 'string') {
9484
proofs.some(
95-
otherProof => otherProof.id == previousProof).
85+
otherProof => otherProof.id == proof.previousProof).
9686
should.equal(true,
9787
'Expected previousProof ' +
98-
`${proof.previousProof} ` +
99-
'to be the id of another included proof.'
88+
`${proof.previousProof} ` +
89+
'to be the id of another included proof.'
10090
);
91+
} if(Array.isArray(proof.previousProof)) {
92+
for(const previousProof in proof.previousProof) {
93+
proofs.some(
94+
otherProof => otherProof.id == previousProof).
95+
should.equal(true,
96+
'Expected previousProof ' +
97+
`${proof.previousProof} ` +
98+
'to be the id of another included proof.'
99+
);
100+
}
101101
}
102102
}
103103
}
104-
}
105-
});
106-
it('If any element of previousProof array has an id attribute \
107-
that does not match the id attribute of any element of allProofs, \
108-
an error MUST be raised.',
109-
function() {
110-
this.test.link = 'https://www.w3.org/TR/vc-data-integrity/#:~:text=If%20any%20element%20of%20previousProof%20array%20has%20an%20id%20attribute%20that%20does%20not%20match%20the%20id%20attribute%20of%20any%20element%20of%20allProofs%2C%20an%20error%20MUST%20be%20raised%20and%20SHOULD%20convey%20an%20error%20type%20of%20PROOF_GENERATION_ERROR.';
111-
const previousProofs = [];
112-
for(const proof of proofs) {
113-
if('previousProof' in proof) {
114-
if(typeof proof.previousProof === 'string') {
115-
previousProofs.push(proof.previousProof);
116-
} if(Array.isArray(proof.previousProof)) {
117-
previousProofs.concat(proof.previousProof);
104+
});
105+
it('If any element of previousProof array has an id attribute' +
106+
' that does not match the id attribute of any element of allProofs,' +
107+
' an error MUST be raised.', function() {
108+
this.test.link = 'https://www.w3.org/TR/vc-data-integrity/#:~:text=If%20any%20element%20of%20previousProof%20array%20has%20an%20id%20attribute%20that%20does%20not%20match%20the%20id%20attribute%20of%20any%20element%20of%20allProofs%2C%20an%20error%20MUST%20be%20raised%20and%20SHOULD%20convey%20an%20error%20type%20of%20PROOF_GENERATION_ERROR.';
109+
const previousProofs = [];
110+
for(const proof of proofs) {
111+
if('previousProof' in proof) {
112+
if(typeof proof.previousProof === 'string') {
113+
previousProofs.push(proof.previousProof);
114+
} if(Array.isArray(proof.previousProof)) {
115+
previousProofs.concat(proof.previousProof);
116+
}
118117
}
119118
}
120-
}
121-
for(const previousProof of previousProofs) {
122-
proofs.some(
123-
otherProof => otherProof.id == previousProof).should.equal(
124-
true,
125-
'Expected all previousProof values to be the id of \
126-
another included proof.'
127-
);
128-
}
129-
});
119+
for(const previousProof of previousProofs) {
120+
proofs.some(
121+
otherProof => otherProof.id == previousProof).should.equal(
122+
true,
123+
'Expected all previousProof values to be the id of \
124+
another included proof.'
125+
);
126+
}
127+
});
128+
}
130129
});
131130
}

0 commit comments

Comments
 (0)