Skip to content

Commit

Permalink
expanded web5-vc-ssi integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
finn-tbd committed Jul 27, 2023
1 parent bcbc229 commit 010c1a4
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 12 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/tests-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,15 @@ jobs:
uses: codecov/codecov-action@eaaf4bedf32dbdc6b720b63067d99c4d77d6047d # v3.1.4
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

- name: start local SSI service
run: git clone https://github.com/TBD54566975/ssi-service && cd ssi-service/build && docker-compose up --build -d && until curl -f http://localhost:8080/health; do sleep 1; done

- name: Run web5 SSI integration tests
run: cd packages/web5 && npm run test:node --ws -- -f ssi --color
env:
SSI_BASE_URL: http://localhost:8080
LOG_SSI_REQUESTS: 'true'

test-with-browsers:
# Run browser tests using macOS so that WebKit tests don't fail under a Linux environment
Expand Down
82 changes: 71 additions & 11 deletions packages/web5/tests/web5-vc-ssi.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import * as testProfile from './fixtures/test-profiles.js';

import { VcApi } from '../src/vc-api.js';
import { TestAgent, TestProfileOptions } from './test-utils/test-user-agent.js';
import { DidKeyApi } from '@tbd54566975/dids';


// import jwt from 'jsonwebtoken';

Expand Down Expand Up @@ -39,31 +41,89 @@ describe('web5.vc.ssi', () => {
it('a verifiable credential', async () => {

console.log('creating vc');
const credentialSubject = {firstName: 'alice'};
const credentialSubject = { firstName: 'alice' };
const result = await vcApi.create(credentialSubject);
expect(result.status.code).to.equal(202);
expect(result.status.detail).to.equal('Accepted');
expect(result.record).to.exist;

console.log('created vc, verifiying it against SSI');

let ssiResponse = await loggableFetch(SSIBaseURL + '/v1/credentials/verification', {
method : 'PUT',
body : JSON.stringify({'credentialJwt': await result.record?.data.text()}),
let ssiResponse = await ssiRequest('/v1/credentials/verification', {
'credentialJwt': await result.record?.data.text(),
});

let ssiVerified = await ssiResponse.json();
console.log(ssiResponse);

console.log(ssiVerified);
expect(ssiResponse.verified).to.be.true;
});
it('a presentation exchange', async () => {
const issuerDID = await ssiRequest('/v1/dids/key', {keyType: 'Ed25519'});
const holderDID = await new DidKeyApi().create();

let credentialResponse = await ssiRequest('/v1/credentials', {
data: {
additionalName : 'Mclovin',
dateOfBirth : '1987-01-02',
familyName : 'Andres',
givenName : 'Uribe'
},
issuer : issuerDID.did.id,
verificationMethodId : issuerDID.did.verificationMethod[0].id,
subject : holderDID.id,
expiry : '2051-10-05T14:48:00.000Z'
});

expect(ssiVerified.verified).to.be.true;
const submissionJWTData = {
vp: {
'@context': [
'https://www.w3.org/2018/credentials/v1'
],
holder : holderDID.id, // go test calls holderDID.Expand() then this is .ID on the result of that. Have not investigated.
type : ['VerifiablePresentation'],
presentation_submission : {
id : '{{.SubmissionID}}', // uuid.NewString()
definition_id : '{{.DefinitionID}}', // PUT /v1/presentations/definitions -> DefinitionID = .presentation_definition.id
descriptor_map : [
{
id : 'wa_driver_license',
format : 'jwt_vp',
path : '$.verifiableCredential[0]'
}
]
},
verifiableCredential: [credentialResponse.credentialJwt]
}
};

const submissionJWT = JSON.stringify(submissionJWTData); // TODO make + sign a JWT out of this data, don't just JSON-encode it
let createSubmissionResponse = await ssiRequest('/v1/presentations/submissions', {submissionJwt: submissionJWT});

expect(createSubmissionResponse.done).to.be.true;
});
});
});
});

function loggableFetch(url: string, init?: RequestInit | undefined): Promise<Response> {
let method = init?.method || 'GET';
console.log(method, ' ', url);
return fetch(url, init);
async function ssiRequest(path: string, body?: any): Promise<any> {
const method = body ? 'PUT' : 'GET'; // method is PUT if a request body is provided, GET if not
const url = SSIBaseURL + path;

if(process.env.LOG_SSI_REQUESTS) {
console.log('>', method, url, body);
}

const init: RequestInit = {method: method};
if(body) {
init.body = JSON.stringify(body);
}

const resp = await fetch(url, init);
const respJSON = await resp.json();

if(process.env.LOG_SSI_REQUESTS) {
console.log('<', resp.status, resp.statusText, ': ', respJSON);
}

return respJSON;
}

0 comments on commit 010c1a4

Please sign in to comment.