Skip to content

Commit

Permalink
Move deriveInvalidVectors to vc-gen.
Browse files Browse the repository at this point in the history
  • Loading branch information
aljones15 committed Jun 14, 2024
1 parent fb5975f commit 2ea5ae4
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 30 deletions.
34 changes: 4 additions & 30 deletions tests/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
*/
import {
deriveCredentials,
deriveInvalidVectors,
getMultikeys,
getSuite,
issueCredentials
} from './vc-generator/index.js';
import {generators, issueCloned} from 'data-integrity-test-suite-assertion';
import {generators} from 'data-integrity-test-suite-assertion';

export async function verifySetup({credentials, keyTypes, suite}) {
const testVectors = {
Expand Down Expand Up @@ -122,34 +122,6 @@ export async function verifySetup({credentials, keyTypes, suite}) {
suite,
keyTypes
});
const deriveInvalidVectors = async ({
keys,
vectors,
map = new Map(),
generators = []
}) => {
for(const [keyType, {signer, issuer}] of keys) {
map.set(keyType, new Map());
for(const [vcVersion, vector] of Object.entries(vectors)) {
const {credential, mandatoryPointers, selectivePointers} = vector;
const _credential = structuredClone(credential);
_credential.issuer = issuer;
// the first params passed to the first generator
const initParams = {
suite: getSuite({suite, signer, mandatoryPointers}),
selectiveSuite: getSuite({suite, signer, selectivePointers}),
credential: _credential
};
// call each generator on itself to produce accumulated invalid suites
// and vectors
const testData = generators.reduce((accumulator, current) =>
current(accumulator), initParams);
const vc = await issueCloned(testData);
map.get(keyType).set(vcVersion, vc);
}
}
return map;
};
const {mandatory, shared} = generators;
const {invalidProofType} = mandatory;
const {invalidCryptosuite} = shared;
Expand All @@ -158,11 +130,13 @@ export async function verifySetup({credentials, keyTypes, suite}) {
await deriveInvalidVectors({
keys,
vectors: subjectNestedObjects,
suiteName: suite,
generators: [invalidProofType, invalidCryptosuite]
});
testVectors.disclosed.invalid.cryptosuite = await deriveInvalidVectors({
keys,
vectors: subjectNestedObjects,
suiteName: suite,
generators: [invalidCryptosuite]
});
return testVectors;
Expand Down
31 changes: 31 additions & 0 deletions tests/vc-generator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import * as vc from '@digitalbazaar/vc';
import {documentLoader as defaultLoader} from './documentLoader.js';
import {getMultikeys} from './key-gen.js';
import {getSuite} from './cryptosuites.js';
import {issueCloned} from 'data-integrity-test-suite-assertion';

/**
* Issues test data locally and then returns a Map
Expand Down Expand Up @@ -136,4 +137,34 @@ export async function verifyCredential({
});
}

export async function deriveInvalidVectors({
keys,
vectors,
map = new Map(),
suiteName,
generators = []
}) {
for(const [keyType, {signer, issuer}] of keys) {
map.set(keyType, new Map());
for(const [vcVersion, vector] of Object.entries(vectors)) {
const {credential, mandatoryPointers, selectivePointers} = vector;
const _credential = structuredClone(credential);
_credential.issuer = issuer;
// the first params passed to the first generator
const initParams = {
suite: getSuite({suite: suiteName, signer, mandatoryPointers}),
selectiveSuite: getSuite({suite: suiteName, signer, selectivePointers}),
credential: _credential
};
// call each generator on itself to produce accumulated invalid suites
// and vectors
const testData = generators.reduce((accumulator, current) =>
current(accumulator), initParams);
const vc = await issueCloned(testData);
map.get(keyType).set(vcVersion, vc);
}
}
return map;
}

export {getSuite, getMultikeys};

0 comments on commit 2ea5ae4

Please sign in to comment.