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

bug(key-manager): wrong schema reference in plugin #22

Open
cre8 opened this issue Jan 19, 2024 · 2 comments
Open

bug(key-manager): wrong schema reference in plugin #22

cre8 opened this issue Jan 19, 2024 · 2 comments

Comments

@cre8
Copy link

cre8 commented Jan 19, 2024

The SphereonKeyManager is appending the Veramo Keymanager with some functions like

async keyManagerVerify(args: ISphereonKeyManagerVerifyArgs): Promise<boolean> {

However the schema value from VeramoKeyManager is not overwritten, it is still pointing to the schema of the veramo pluging that is not including these new functions. This will lead to an error when exposing the methods via the remote service since the object keyManagerVerify does not exist in the schema.

Solution:
override the schema in

export class SphereonKeyManager extends VeramoKeyManager {
with the plugin.schema.json that is including the function.

@cre8
Copy link
Author

cre8 commented Jan 19, 2024

Importing the schema json file with

import schema from '../../plugin.schema.json' assert { type: 'json' }

and then setting the schema like: readonly schema = schema.ISphereonKeyManager

Should work. However we need to update the tsconfig.json by setting module to ESNext to support assertion imports.

This leads to a problem:

  • to run the build command, we need the plugin.schema.json file
  • we need the builded code to generate the pluging.schema.json file

Beside the current file is generated outside of the rootDir of the project so it can not be referenced (I tried to include it with the file command is the tsconfig but without success)

@cre8
Copy link
Author

cre8 commented Jan 19, 2024

In the meantime it can be patched like:

diff --git a/node_modules/@sphereon/ssi-sdk-ext.key-manager/dist/agent/SphereonKeyManager.js b/node_modules/@sphereon/ssi-sdk-ext.key-manager/dist/agent/SphereonKeyManager.js
index 28aa003..ea5c1b1 100644
--- a/node_modules/@sphereon/ssi-sdk-ext.key-manager/dist/agent/SphereonKeyManager.js
+++ b/node_modules/@sphereon/ssi-sdk-ext.key-manager/dist/agent/SphereonKeyManager.js
@@ -12,6 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
 exports.SphereonKeyManager = void 0;
 const key_manager_1 = require("@veramo/key-manager");
 const ssi_sdk_ext_kms_local_1 = require("@sphereon/ssi-sdk-ext.kms-local");
+const schema = require('../../plugin.schema.json');
 class SphereonKeyManager extends key_manager_1.KeyManager {
     constructor(options) {
         super({ store: options.store, kms: options.kms });
@@ -20,6 +21,15 @@ class SphereonKeyManager extends key_manager_1.KeyManager {
         const methods = this.methods;
         methods.keyManagerVerify = this.keyManagerVerify.bind(this);
         this.localMethods = methods;
+        //append the SphereonKeyManager schema to the agent schema
+        this.schema.components.schemas = {
+          ...this.schema.components.schemas,
+          ...schema.ISphereonKeyManager.components.schemas,
+        }
+        this.schema.components.methods = {
+          ...this.schema.components.methods,
+          ...schema.ISphereonKeyManager.components.methods,
+        }
     }
     getLocalKms(name) {
         const kms = this.localKms[name];

We cannot just overwrite it, it needs to be appended.

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

1 participant