Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: make getInstanceOpts from SIOPv2RP fetching from the DB #153

Open
cre8 opened this issue Jan 17, 2024 · 3 comments
Open

feature: make getInstanceOpts from SIOPv2RP fetching from the DB #153

cre8 opened this issue Jan 17, 2024 · 3 comments

Comments

@cre8
Copy link

cre8 commented Jan 17, 2024

right now the the instances have to be passed to the constructor and are saved in a read only variable. My current solution is to read the values from the key value store and the pass it to the plugin:

const instanceOpts: IPEXInstanceOptions[] = await rep
    .find({ where: { key: Like('%oid4vp%') } })
    .then((res) =>
      res.map((r) => {
        const content = JSON.parse(r.data).value as IPresentationDefinition;
        return {
          definitionId: content.id,
          definition: content,
        } as IPEXInstanceOptions;
      })
    );

  return [
    new CredentialPlugin(),
    new PresentationExchange({
      stores: new KeyValueStore({
        namespace: 'oid4vp',
        store: new KeyValueTypeORMStoreAdapter({
          dbConnection: agentConfig.datasource,
        }),
      }),
    }),
    new SIOPv2RP({
      defaultOpts: {
        didOpts: {
          checkLinkedDomains: CheckLinkedDomain.IF_PRESENT,
          identifierOpts: {
            identifier,
            kid,
          },
        },
      },
      instanceOpts,
    }),

Would it be possible to implement this call directly into the siopv2RP instance so we don't have to restart it? Or at least make the variable olding the definitions public so we can patch it from outside (maybe via a new version).

Is this already covered on your roadmap? If not I would like to implement it :)

@nklomp
Copy link
Contributor

nklomp commented Jan 19, 2024

Yeah, In all honesty the current approach we take needs a bit of an overhaul.

One thing which would be a nice approach is to emit an event from the key value store, which the siop plugin picks up

@cre8
Copy link
Author

cre8 commented Jan 19, 2024

In the meantime I am patching the value from outside like:

  setInterval(async () => {
    const rep = agentConfig.datasource.getRepository(KeyValueStoreEntity);
    //TODO: this is not the preferred way since we need to reload the application to get the latest version.
    const instanceOpts: IPEXInstanceOptions[] = await rep
      .find({ where: { key: Like('%oid4vp%') } })
      .then((res) =>
        res.map((r) => {
          const content = JSON.parse(r.data).value as IPresentationDefinition;
          return {
            definitionId: content.id,
            definition: content,
          } as IPEXInstanceOptions;
        })
      );
    //@ts-ignore
    siop.opts.instanceOpts = instanceOpts;
  }, 1500);

Not the best way, but it gets the job done for now

The event approach would be nice. However I think right now veramo was designed that listener can only be registered on the plugin level and not directly in a plugin (could be changed easily of course).

@cre8
Copy link
Author

cre8 commented Mar 7, 2024

Btw my posted solution only works when the presentation was not requested yet. Because when it did, the instance is managed in an internal map and therefore the update of instanceOpts is not working. Maybe you can patch the existing entries, but safest way is to restart the whole agent (with the risk of loosing open sessions)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants