Skip to content

Commit

Permalink
adding test vector
Browse files Browse the repository at this point in the history
  • Loading branch information
nitro-neal committed Dec 8, 2023
1 parent 01ece16 commit 7b59d5b
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/credentials/src/presentation-exchange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ export class PresentationExchange {
): string[] {
this.resetPex();
const selectResults: SelectResults = this.pex.selectFrom(presentationDefinition, vcJwts);
return selectResults.verifiableCredential as string[] ?? [];
const selectedCredentials = selectResults.verifiableCredential as string[] ?? [];
return [...new Set(selectedCredentials)];
}

/**
Expand Down
17 changes: 17 additions & 0 deletions packages/credentials/tests/presentation-exchange.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import fs from 'fs';
import { expect } from 'chai';
import { DidKeyMethod, PortableDid } from '@web5/dids';
import { PresentationExchange, Validated, PresentationDefinitionV2 } from '../src/presentation-exchange.js';
Expand Down Expand Up @@ -163,6 +164,22 @@ describe('PresentationExchange', () => {
expect(warnings?.length).to.equal(0);
});
});

describe('Presentation Exchange Spec', () => {
it('select_credentials_v1', async () => {
const jsonString = fs.readFileSync('../../test-vectors/presentation-exchange/select-credentials-v1.json', 'utf8');
const vectors = JSON.parse(jsonString).vectors;

for (let i = 0; i < vectors.length; i++) {
const input = vectors[i].input;
const expectedOutput = vectors[i].output.selectedCredentials;

const selectedCreds = await PresentationExchange.selectCredentials(input.credentialJwts, input.presentationDefinition);

expect(selectedCreds).to.deep.equals(expectedOutput);
}
});
});
});

function createPresentationDefinition(): PresentationDefinitionV2 {
Expand Down
59 changes: 59 additions & 0 deletions test-vectors/presentation-exchange/select-credentials-v1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"description":"Select Credentials",
"vectors":[
{
"description":"select credentials for presentation",
"input":{
"presentationDefinition":{
"id":"test-pd-id",
"name":"simple PD",
"purpose":"pd for testing",
"input_descriptors":[
{
"id":"whatever",
"purpose":"id for testing",
"constraints":{
"fields":[
{
"path":[
"$.vc.credentialSubject.btcAddress",
"$.credentialSubject.btcAddress",
"$.btcAddress"
]
}
]
}
},
{
"id":"whatever2",
"purpose":"id for testing2",
"constraints":{
"fields":[
{
"path":[
"$.vc.credentialSubject.dogeAddress",
"$.credentialSubject.dogeAddress",
"$.dogeAddress"
]
}
]
}
}
]
},
"credentialJwts":[
"eyJ0eXAiOiJKV1QiLCJhbGciOiJFZERTQSIsImtpZCI6ImRpZDprZXk6ejZNa2ZIQk5tYzRjQ2hOdER2YXIxOFRaaWdmWHQ3UDY1RkJHd3FRVHR4UW9RUG5HI3o2TWtmSEJObWM0Y0NoTnREdmFyMThUWmlnZlh0N1A2NUZCR3dxUVR0eFFvUVBuRyJ9.eyJpc3MiOiJkaWQ6a2V5Ono2TWtmSEJObWM0Y0NoTnREdmFyMThUWmlnZlh0N1A2NUZCR3dxUVR0eFFvUVBuRyIsInN1YiI6ImRpZDprZXk6ejZNa2ZIQk5tYzRjQ2hOdER2YXIxOFRaaWdmWHQ3UDY1RkJHd3FRVHR4UW9RUG5HIiwidmMiOnsiQGNvbnRleHQiOlsiaHR0cHM6Ly93d3cudzMub3JnLzIwMTgvY3JlZGVudGlhbHMvdjEiXSwidHlwZSI6WyJWZXJpZmlhYmxlQ3JlZGVudGlhbCIsIlN0cmVldENyZWQiXSwiaWQiOiJ1cm46dXVpZDoxM2Q1YTg3YS1kY2Y1LTRmYjktOWUyOS0wZTYyZTI0YzQ0ODYiLCJpc3N1ZXIiOiJkaWQ6a2V5Ono2TWtmSEJObWM0Y0NoTnREdmFyMThUWmlnZlh0N1A2NUZCR3dxUVR0eFFvUVBuRyIsImlzc3VhbmNlRGF0ZSI6IjIwMjMtMTItMDdUMTc6MTk6MTNaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6a2V5Ono2TWtmSEJObWM0Y0NoTnREdmFyMThUWmlnZlh0N1A2NUZCR3dxUVR0eFFvUVBuR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