w3c-ccg / vc-test-suite-implementations

Implementations for VC HTTP API tests
BSD 3-Clause "New" or "Revised" License
0 stars 11 forks source link

Generalize `Issuer` & `Verifier` classes into Endpoint Class #30

Closed aljones15 closed 2 years ago

aljones15 commented 2 years ago

We are increasingly in need of multiple endpoints that are not necessarily issuers and verifiers. For instance we need to call on did-resolvers, status list, and in the near future vc-refesh endpoints. There for I propose that we abstract the Issuer and Verifier classes into an Endpoint class.

That class would look like something this:

export Class Endpoint {
  constructor({oauth2, settings}) {

  }
  get tags() {
    return new Set(this.settings.tags);
  }
  async post({body, headers}) {
    const {settings, oauth2} = this;
    const headers = {...settings.headers};
    if(isettings.zcap) {
      return zcapRequest({
        endpoint: settings.endpoint,
        zcap: settings.zcap,
        json: body,
        headers
      }); 
    }   
    return httpPost({
      endpoint: issuer.endpoint,
      oauth2,
      json: body,
      headers
    }); 
  // same logic for GET, PUT, etc
}

This also condenses redundant code from Issuer and Verifier into a single class that does more than the existing classes do now. It also allows people to add new endpoints to their implementation config file with out us having to explicitly cast it to an Issuer or Verifier class.

The new flow would look for properties in the implementation config and then would wrap each element of a property that is an Array into an Array of Endpoint classes.

Example:

{
  "name": "Example Implementation",
  "implementation": "example",
  "issuers": [{
    "id": "did:key:Example",
    "endpoint": "https://example.com/1.0/credentials/issue",
    "options": {
      "type": "Ed25519Signature2018"
    },
    "tags": ["VC-API"]
  }],
  "verifiers": [{
    "id": "urn:uuid:not-a-uuid",
    "endpoint": "https://example.com/1.0/credentials/verify",
    "tags": ["VC-API", "Ed25519Signature2020"]
  }],
  "didResolvers": [{
    "id": "",
    "endpoint": "https://dev.uniresolver.io/1.0/identifiers",
    "tags": ["Did-Key"]
  }],
  "some-new-endpoint": [{
     "id": "",
     "endpoint": "https://www.example.com/some-new-endpoint",
     "tags": ["new-test"]
  }]
}

// all of the Arrays are cast to `Class Endpoint`
// so we now filter like this

const {implemented, notImplemented} = filterByTag({property: 'some-new-endpoint', tags: ['new-test']})
// each entry in implemented already has all HTTP methods set up so we're good to go for testing

So basically:

  1. Create a new higher level Class that combines Issuer & Verifier code into a single class
  2. Use that higher level Class to deal with new endpoint automatically
  3. DRY up some of the request logic
  4. Makes this package better able to handle future tests and endpoints
aljones15 commented 2 years ago

Closing as this has been addressed.