Skip to content

Commit

Permalink
Switch from endpoints.createVp to createLocalVp.
Browse files Browse the repository at this point in the history
  • Loading branch information
aljones15 committed Sep 19, 2024
1 parent 04fc3a2 commit 1e0495c
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 17 deletions.
11 changes: 6 additions & 5 deletions tests/4-3-contexts.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import {addPerTestMetadata, setupMatrix} from './helpers.js';
import assert from 'node:assert/strict';
import chai from 'chai';
import {createLocalVp} from './data-generator.js';
import {createRequire} from 'module';
import {filterByTag} from 'vc-test-suite-implementations';
import {TestEndpoints} from './TestEndpoints.js';
Expand Down Expand Up @@ -49,7 +50,7 @@ describe('Contexts', function() {
it('Verifiable presentations MUST include a @context property.',
async function() {
this.test.link = `https://w3c.github.io/vc-data-model/#types:~:text=Verifiable%20credentials%20and%20verifiable%20presentations%20MUST%20include%20a%20%40context%20property.`;
const vp = await endpoints.createVp({
const vp = await createLocalVp({
presentation: require('./input/presentation-ok.json')
});
vp.should.have.property('@context').to.be.an('array',
Expand Down Expand Up @@ -80,7 +81,7 @@ describe('Contexts', function() {
'property MUST be an ordered set where the first item is a URL with ' +
'the value https://www.w3.org/ns/credentials/v2.', async function() {
this.test.link = `https://w3c.github.io/vc-data-model/#types:~:text=The%20value%20of%20the%20%40context%20property%20MUST%20be%20an%20ordered%20set%20where%20the%20first%20item%20is%20a%20URL%20with%20the%20value%20https%3A//www.w3.org/ns/credentials/v2.`;
const vp = await endpoints.createVp({
const vp = await createLocalVp({
presentation: require('./input/presentation-ok.json')
});
assert(Array.isArray(vp['@context']),
Expand Down Expand Up @@ -119,19 +120,19 @@ describe('Contexts', function() {
async function() {
this.test.link = `https://w3c.github.io/vc-data-model/#types:~:text=Subsequent%20items%20in%20the%20ordered%20set%20MUST%20be%20composed%20of%20any%20combination%20of%20URLs%20and/or%20objects%2C%20where%20each%20is%20processable%20as%20a%20JSON%2DLD%20Context.`;
await assert.doesNotReject(
endpoints.verifyVp(await endpoints.createVp({
endpoints.verifyVp(await createLocalVp({
presentation:
require('./input/presentation-context-combo1-ok.json')
})),
'Failed to support multiple `@context` URLs in a VP.');
await assert.doesNotReject(
endpoints.verifyVp(await endpoints.createVp({
endpoints.verifyVp(await createLocalVp({
presentation:
require('./input/presentation-context-combo2-ok.json')
})),
'Failed to support objects in the `@context` Array in a VP.');
// first create a valid VP
const vp = await endpoints.createVp({
const vp = await createLocalVp({
presentation: require('./input/presentation-vc-ok.json')
});
// then inject incorrect `@context` values and test verification
Expand Down
3 changes: 2 additions & 1 deletion tests/4-5-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import {addPerTestMetadata, setupMatrix} from './helpers.js';
import assert from 'node:assert/strict';
import chai from 'chai';
import {createLocalVp} from './data-generator.js';
import {createRequire} from 'module';
import {filterByTag} from 'vc-test-suite-implementations';
import {TestEndpoints} from './TestEndpoints.js';
Expand Down Expand Up @@ -99,7 +100,7 @@ describe('Types', function() {
it('Verifiable Presentation objects MUST have a type specified.',
async function() {
this.test.link = `https://w3c.github.io/vc-data-model/#types:~:text=the%20following%20table%20lists%20the%20objects%20that%20MUST%20have%20a%20type%20specified.`;
const presentationOptionalType = await endpoints.createVp({
const presentationOptionalType = await createLocalVp({
presentation: require('./input/presentation-optional-type-ok.json')
});
await assert.doesNotReject(endpoints.verifyVp(
Expand Down
7 changes: 4 additions & 3 deletions tests/413-verifiable-presentations.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import {addPerTestMetadata, setupMatrix} from './helpers.js';
import assert from 'node:assert/strict';
import chai from 'chai';
import {createLocalVp} from './data-generator.js';
import {createRequire} from 'module';
import {filterByTag} from 'vc-test-suite-implementations';
import {TestEndpoints} from './TestEndpoints.js';
Expand All @@ -31,7 +32,7 @@ describe('Verifiable Presentations', function() {
it('If [the `id` field is] present, the normative guidance in Section ' +
'4.4 Identifiers MUST be followed.', async function() {
this.test.link = `https://w3c.github.io/vc-data-model/#verifiable-presentations:~:text=verifiable%20presentation.-,If%20present%2C%20the%20normative%20guidance%20in%20Section%204.4%20Identifiers%20MUST%20be%20followed.,-type`;
const presentationWithCredential = await endpoints.createVp({
const presentationWithCredential = await createLocalVp({
presentation: require('./input/presentation-vc-ok.json')
});
if('id' in presentationWithCredential) {
Expand All @@ -49,7 +50,7 @@ describe('Verifiable Presentations', function() {
'The related normative guidance in Section 4.5 Types MUST be followed.',
async function() {
this.test.link = `https://w3c.github.io/vc-data-model/#verifiable-presentations:~:text=The%20type%20property%20MUST%20be%20present.%20It%20is%20used%20to%20express%20the%20type%20of%20verifiable%20presentation.%20One%20value%20of%20this%20property%20MUST%20be%20VerifiablePresentation%2C%20but%20additional%20types%20MAY%20be%20included.%20The%20related%20normative%20guidance%20in%20Section%204.5%20Types%20MUST%20be%20followed.`;
const presentationWithCredential = await endpoints.createVp({
const presentationWithCredential = await createLocalVp({
presentation: require('./input/presentation-vc-ok.json')
});
presentationWithCredential.should.have.property('type').that.contains(
Expand All @@ -65,7 +66,7 @@ describe('Verifiable Presentations', function() {
this.test.link = `https://w3c.github.io/vc-data-model/#verifiable-presentations:~:text=The%20verifiableCredential%20property%20MAY%20be%20present.%20The%20value%20MUST%20be%20one%20or%20more%20verifiable%20credential%20and/or%20enveloped%20verifiable%20credential%20objects%20(the%20values%20MUST%20NOT%20be%20non%2Dobject%20values%20such%20as%20numbers%2C%20strings%2C%20or%20URLs).`;
// TODO: Test with remote presentation creation or querying if/when
// supported by the implementation
const presentationWithCredentials = await endpoints.createVp({
const presentationWithCredentials = await createLocalVp({
presentation: require('./input/presentation-multiple-vc-ok.json')
});
await assert.doesNotReject(endpoints.verifyVp(
Expand Down
10 changes: 4 additions & 6 deletions tests/TestEndpoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
* SPDX-License-Identifier: LicenseRef-w3c-3-clause-bsd-license-2008 OR LicenseRef-w3c-test-suite-license-2023
*/

import {challenge, createVp} from './data-generator.js';
import {
createRequestBody,
createVerifyRequestBody
} from './mock.data.js';
import {challenge} from './data-generator.js';
import http from 'http';
import receiveJson from './receive-json.js';

Expand All @@ -28,11 +28,9 @@ export class TestEndpoints {
const issueBody = createRequestBody({issuer, vc: credential});
return post(issuer, issueBody);
}
async createVp({presentation, options = {}}) {
return createVp({presentation, options: {
challenge,
...options
}});
// FIXME implement createVp in the future
async createVp() {
throw new Error('Create VP not implemented yet.');
}
async verify(vc) {
const verifyBody = createVerifyRequestBody({vc});
Expand Down
4 changes: 2 additions & 2 deletions tests/data-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ async function getKeys() {
}

/**
* An extremely basic VP creator. This is not final
* An extremely basic local VP creator. This is not final
* and will probably change.
*
* @param {object} options - Options to use.
Expand All @@ -68,7 +68,7 @@ async function getKeys() {
*
* @returns {Promise<object>} Resolves to a signed VP.
*/
export async function createVp({presentation, options = {}}) {
export async function createLocalVp({presentation, options = {challenge}}) {
const {signer, keyPair} = await getKeys({options});
options.suite = new DataIntegrityProof({
signer,
Expand Down

0 comments on commit 1e0495c

Please sign in to comment.