filip26 / iron-verifiable-credentials

A Verifiable Credentials Processor & API
https://apicatalog.com
Apache License 2.0
15 stars 7 forks source link

Allow extension of DocumentLoader cache #145

Open lemoustachiste opened 6 months ago

lemoustachiste commented 6 months ago

Hi,

I'm facing an issue with loading of remote context urls, and while I have found this: https://github.com/filip26/iron-verifiable-credentials/blob/main/src/main/java/com/apicatalog/vc/loader/StaticContextLoader.java#L39, there does not seem to be a way to extend that cached list with a customer's dedicated list.

I'm going to write my own DocumentLoader as I can specify one here https://github.com/filip26/iron-verifiable-credentials/blob/main/src/main/java/com/apicatalog/vc/holder/Holder.java#L54 (thanks for that) but as it seems I will have redundant properties and it would have been nice to leverage the one that is already available in the library.

Nothing critical but I think it would be a nice-to-have

filip26 commented 3 months ago

What do you think about this?

// Extend StaticContextLoader application wide
static {
  // pre-load resource from classpath
  StaticContextLoader.set(url, SomeClass.class, "name.jsonld");
  // set JSON document directly
  StaticContextLoader.set(url, document);   
}
lemoustachiste commented 3 months ago

It's been a while but that looks like an easy enough API to consume.

The expectation would be that later on, by injecting the StaticContextLoader as DocumentLoader, any url/document pair set would be available for retrieval (through .loadDocument (https://github.com/filip26/iron-verifiable-credentials/blob/main/src/main/java/com/apicatalog/vc/loader/StaticContextLoader.java#L28)).

DigitalBazaar's API is named addStatic (https://github.com/digitalbazaar/security-document-loader/blob/main/lib/security-loader.js#L22) so that's another option but set is understandable enough in the context of this class (by opposition to get).