decentralized-identity / veramo-plugin

Veramo plugin template
http://veramo.io/docs/guides/create_plugin
2 stars 3 forks source link

[BUG] Setup doesn't work #28

Closed VargaElod23 closed 4 months ago

VargaElod23 commented 12 months ago

Prerequisites

Please answer the following questions for yourself before submitting an issue.

YOU MAY DELETE THE PREREQUISITES SECTION if you're sure you checked all the boxes.

Current Behavior

What is the current behavior?

Expected Behavior

Hey guys! Please follow your own setup steps for this minimalistic server and see that it doesn't work using node v18.15.0. Expected:

Please include any relevant log snippets or files here. Create a GIST which is a paste of your full or sanitized logs, and link them here. Please do NOT paste your full logs here, as it will make this issue very long and hard to read!

Alternatives you considered

Please provide details about an environment where this bug does not occur.


Don't paste private keys anywhere public!

jaycoolslm commented 12 months ago

Same here.

In agent.yml if I update - - $require: 'cors to - - $require: 'cors?t=function#default then the undefined cors error go, but there are still other errors

dennisn00 commented 7 months ago

If you get errors like Directory import '.../veramo-plugin/build' is not supported resolving ES modules imported from ..., the problem is in agent.yml. Replace all imports of your local implementations like $require: ./build#MyAgentPlugin or $require: ./build#MyKeyManagementSystem with the full path, for example $require: ./build/agent-plugin/my-plugin.js#MyAgentPlugin

jaycoolslm commented 4 months ago

Still getting same errors at the same point, is there anything from veramo team on this?

dennisn00 commented 4 months ago

Could you describe in detail what you are doing and what error message you are getting?

jaycoolslm commented 4 months ago
  1. clone repo
  2. yarn
  3. yarn build
  4. yarn generate-plugin-schema
  5. yarn start

Then I get this error: Error creating cors['undefined']: required is not a constructor. While creating object from pointer: /server

If I rename server: use:

dennisn00 commented 4 months ago

Can you post the error message for the js import errors?

jaycoolslm commented 4 months ago

Error creating /Users/jaycool/code/veramo/veramo-plugin/build['MyKeyManagementSystem']: Directory import '/Users/jaycool/code/veramo/veramo-plugin/build' is not supported resolving ES modules imported from /Users/jaycool/code/veramo/veramo-plugin/node_modules/@veramo/cli/build/lib/objectCreator.js Did you mean to import /Users/jaycool/code/veramo/veramo-plugin/build/index.js?. While creating object from pointer: /keyManager. While creating object from pointer: /agent. While creating object from pointer: /server error Command failed with exit code 1.

nickreynolds commented 4 months ago

Can you share what version of node you're using? I just did a fresh clone and was able to generate schema on node v20.14.0

jaycoolslm commented 4 months ago

I am running node v20.3.1

yarn generate-plugin-schema <- this command works

Where I am getting an error is at yarn start

jaycoolslm commented 4 months ago

I just bumped up to v20.14.0 and still same errors when running yarn start

If I dont update the require cors line in the agent.yml file I get Error creating cors['undefined']: required is not a constructor. While creating object from pointer: /server

When I do update the file withe the cors query params I get this error: Error creating /Users/jaycool/code/veramo/veramo-plugin/build['MyKeyManagementSystem']: Directory import '/Users/jaycool/code/veramo/veramo-plugin/build' is not supported resolving ES modules imported from /Users/jaycool/code/veramo/veramo-plugin/node_modules/@veramo/cli/build/lib/objectCreator.js Did you mean to import "/Users/jaycool/code/veramo/veramo-plugin/build/index.js"?. While creating object from pointer: /keyManager. While creating object from pointer: /agent. While creating object from pointer: /server

dennisn00 commented 4 months ago

Can you post the content of your agent.yml?

jaycoolslm commented 4 months ago
## This is an example configuration that uses the plugin and customizations from this template
## alongside other default plugins to create an agent using `@veramo/cli`.
##
## Look for the `__TEMPLATE__: ` prefix in comments to see where things fit
##

version: 3.0

constants:
  baseUrl: http://localhost:3335
  port: 3335
# please use your own X25519 key, this is only an example
  secretKey: 29739248cad1bd1a0fc4d9b75cd4d2990de535baf5caadfdf8d8f86664aa830c
  databaseFile: ./database.sqlite
  methods:
    # This is the list of methods that may be executed on this agent.
    # Methods that are NOT listed here cannot be executed, even if the plugins that implement them are installed.
    - keyManagerGetKeyManagementSystems
    - keyManagerCreate
    - keyManagerGet
    - keyManagerDelete
    - keyManagerImport
    - keyManagerEncryptJWE
    - keyManagerDecryptJWE
    - keyManagerSign
    - keyManagerSharedSecret
    - keyManagerSignJWT
    - keyManagerSignEthTX
    - didManagerGetProviders
    - didManagerFind
    - didManagerGet
    - didManagerCreate
    - didManagerGetOrCreate
    - didManagerImport
    - didManagerDelete
    - didManagerAddKey
    - didManagerRemoveKey
    - didManagerAddService
    - didManagerRemoveService
    - resolveDid
    - getDIDComponentById
    - dataStoreGetMessage
    - dataStoreSaveMessage
    - dataStoreGetVerifiableCredential
    - dataStoreSaveVerifiableCredential
    - dataStoreGetVerifiablePresentation
    - dataStoreSaveVerifiablePresentation
    - dataStoreORMGetIdentifiers
    - dataStoreORMGetIdentifiersCount
    - dataStoreORMGetMessages
    - dataStoreORMGetMessagesCount
    - dataStoreORMGetVerifiableCredentialsByClaims
    - dataStoreORMGetVerifiableCredentialsByClaimsCount
    - dataStoreORMGetVerifiableCredentials
    - dataStoreORMGetVerifiableCredentialsCount
    - dataStoreORMGetVerifiablePresentations
    - dataStoreORMGetVerifiablePresentationsCount
    - handleMessage
    - packDIDCommMessage
    - unpackDIDCommMessage
    - sendDIDCommMessage
    - sendMessageDIDCommAlpha1
    - createVerifiablePresentation
    - createVerifiableCredential
    - createSelectiveDisclosureRequest
    - getVerifiableCredentialsForSdr
    - validatePresentationAgainstSdr
    # __TEMPLATE__: add your plugin methods here too. This assumes that your plugin is added to the agent. See below, toward the end of this config file.
    - myPluginFoo

# Database
dbConnection:
  $require: typeorm#DataSource
  $args:
    - type: sqlite
      database:
        $ref: /constants/databaseFile
      synchronize: false
      migrationsRun: true
      migrations:
        $require: '@veramo/data-store?t=object#migrations'
      logging: false
      entities:
        $require: '@veramo/data-store?t=object#Entities'

# Server configuration
server:
  baseUrl:
    $ref: /constants/baseUrl
  port:
    $ref: /constants/port
  use:
    # CORS
    - - $require: 'cors?t=function#default'

    # Add agent to the request object
    - - $require: '@veramo/remote-server?t=function#RequestWithAgentRouter'
        $args:
          - agent:
              $ref: /agent

    # DID Documents
    - - $require: '@veramo/remote-server?t=function#WebDidDocRouter'

    # API base path
    - - /messaging
      - $require: '@veramo/remote-server?t=function#MessagingRouter'
        $args:
          - metaData:
              type: DIDComm
              value: https

    # API base path
    - - /agent
      - $require: '@veramo/remote-server?t=function#apiKeyAuth'
        $args:
          # Please configure your own API key. This is used when executing agent methods through ${baseUrl}/agent or ${baseUrl}/api-docs
          - apiKey: test123
      - $require: '@veramo/remote-server?t=function#AgentRouter'
        $args:
          - exposedMethods:
              $ref: /constants/methods

    # Open API schema
    - - /open-api.json
      - $require: '@veramo/remote-server?t=function#ApiSchemaRouter'
        $args:
          - basePath: :3335/agent
            securityScheme: bearer
            apiName: Agent
            apiVersion: '1.0.0'
            exposedMethods:
              $ref: /constants/methods

    # Swagger docs
    - - /api-docs
      - $require: swagger-ui-express?t=object#serve
      - $require: swagger-ui-express?t=function#setup
        $args:
          - null
          - swaggerOptions:
              url: '/open-api.json'

  # Execute during server initialization
  init:
    - $require: '@veramo/remote-server?t=function#createDefaultDid'
      $args:
        - agent:
            $ref: /agent
          baseUrl:
            $ref: /constants/baseUrl
          messagingServiceEndpoint: /messaging

# Message handler plugin
messageHandler:
  $require: '@veramo/message-handler#MessageHandler'
  $args:
    - messageHandlers:
        # order matters
        - $require: '@veramo/did-comm#DIDCommMessageHandler'
        - $require: '@veramo/did-jwt#JwtMessageHandler'
        - $require: '@veramo/credential-w3c#W3cMessageHandler'
        - $require: '@veramo/selective-disclosure#SdrMessageHandler'

# DID resolvers
didResolver:
  $require: '@veramo/did-resolver#DIDResolverPlugin'
  $args:
    - resolver:
        $require: did-resolver#Resolver
        $args:
          - ethr:
              $ref: /ethr-did-resolver
            web:
              $ref: /web-did-resolver
            key:
              $ref: /did-key-resolver
            elem:
              $ref: /universal-resolver
            io:
              $ref: /universal-resolver
            ion:
              $ref: /universal-resolver
            sov:
              $ref: /universal-resolver

ethr-did-resolver:
  $require: ethr-did-resolver?t=function&p=/ethr#getResolver
  $args:
    - infuraProjectId: 5ffc47f65c4042ce847ef66a3fa70d4c

web-did-resolver:
  $require: web-did-resolver?t=function&p=/web#getResolver

universal-resolver:
  $require: '@veramo/did-resolver#UniversalResolver'
  $args:
    - url: https://dev.uniresolver.io/1.0/identifiers/

did-key-resolver:
  $require: '@veramo/did-provider-key?t=function&p=/key#getDidKeyResolver'

# Key Manager
keyManager:
  $require: '@veramo/key-manager#KeyManager'
  $args:
    - store:
        $require: '@veramo/data-store#KeyStore' # __TEMPLATE__: or you can use './build#MyKeyStore' instead
        $args:
          - $ref: /dbConnection
      kms:
        local:
          $require: '@veramo/kms-local#KeyManagementSystem'
          $args:
            - $require: '@veramo/data-store#PrivateKeyStore' # __TEMPLATE__: or you can use './build#MyPrivateKeyStore' instead
              $args:
                - $ref: /dbConnection
                - $require: '@veramo/kms-local#SecretBox'
                  $args:
                    - $ref: /constants/secretKey
        # __TEMPLATE__: you can install your own Key Management System implementation too
        my:
          $require: ./build#MyKeyManagementSystem

# DID Manager
didManager:
  $require: '@veramo/did-manager#DIDManager'
  $args:
    - store:
        $require: '@veramo/data-store#DIDStore' # __TEMPLATE__: or you can use './build#MyDIDStore'
        $args:
          - $ref: /dbConnection
      defaultProvider: did:ethr:goerli
      providers:
        # __TEMPLATE__: you can install your customized DID provider like so
        did:my:
          $require: ./build#MyIdentifierProvider
          $args:
            - defaultKms: local
        did:ethr:
          $require: '@veramo/did-provider-ethr#EthrDIDProvider'
          $args:
            - defaultKms: local
              network: mainnet
              rpcUrl: https://mainnet.infura.io/v3/5ffc47f65c4042ce847ef66a3fa70d4c
              gas: 1000001
              ttl: 31104001
        did:ethr:goerli:
          $require: '@veramo/did-provider-ethr#EthrDIDProvider'
          $args:
            - defaultKms: local
              network: goerli
              rpcUrl: https://goerli.infura.io/v3/5ffc47f65c4042ce847ef66a3fa70d4c
              gas: 1000001
              ttl: 31104001
        did:web:
          $require: '@veramo/did-provider-web#WebDIDProvider'
          $args:
            - defaultKms: local

# Agent
agent:
  $require: '@veramo/core#Agent'
  $args:
    - schemaValidation: false
      plugins:
        - $ref: /keyManager
        - $ref: /didManager
        - $ref: /didResolver
        - $ref: /messageHandler
        - $require: '@veramo/did-comm#DIDComm'
        - $require: '@veramo/credential-w3c#CredentialIssuer'
        - $require: '@veramo/selective-disclosure#SelectiveDisclosure'
        - $require: '@veramo/data-store#DataStore'
          $args:
            - $ref: /dbConnection
        - $require: '@veramo/data-store#DataStoreORM'
          $args:
            - $ref: /dbConnection
          # __TEMPLATE__: install your plugin on the `@veramo/cli` agent
        - $require: ./build#MyAgentPlugin
##
## This is an example configuration that uses the plugin and customizations from this template
## alongside other default plugins to create an agent using `@veramo/cli`.
##
## Look for the `__TEMPLATE__: ` prefix in comments to see where things fit
##

version: 3.0

constants:
  baseUrl: http://localhost:3335
  port: 3335
# please use your own X25519 key, this is only an example
  secretKey: 29739248cad1bd1a0fc4d9b75cd4d2990de535baf5caadfdf8d8f86664aa830c
  databaseFile: ./database.sqlite
  methods:
    # This is the list of methods that may be executed on this agent.
    # Methods that are NOT listed here cannot be executed, even if the plugins that implement them are installed.
    - keyManagerGetKeyManagementSystems
    - keyManagerCreate
    - keyManagerGet
    - keyManagerDelete
    - keyManagerImport
    - keyManagerEncryptJWE
    - keyManagerDecryptJWE
    - keyManagerSign
    - keyManagerSharedSecret
    - keyManagerSignJWT
    - keyManagerSignEthTX
    - didManagerGetProviders
    - didManagerFind
    - didManagerGet
    - didManagerCreate
    - didManagerGetOrCreate
    - didManagerImport
    - didManagerDelete
    - didManagerAddKey
    - didManagerRemoveKey
    - didManagerAddService
    - didManagerRemoveService
    - resolveDid
    - getDIDComponentById
    - dataStoreGetMessage
    - dataStoreSaveMessage
    - dataStoreGetVerifiableCredential
    - dataStoreSaveVerifiableCredential
    - dataStoreGetVerifiablePresentation
    - dataStoreSaveVerifiablePresentation
    - dataStoreORMGetIdentifiers
    - dataStoreORMGetIdentifiersCount
    - dataStoreORMGetMessages
    - dataStoreORMGetMessagesCount
    - dataStoreORMGetVerifiableCredentialsByClaims
    - dataStoreORMGetVerifiableCredentialsByClaimsCount
    - dataStoreORMGetVerifiableCredentials
    - dataStoreORMGetVerifiableCredentialsCount
    - dataStoreORMGetVerifiablePresentations
    - dataStoreORMGetVerifiablePresentationsCount
    - handleMessage
    - packDIDCommMessage
    - unpackDIDCommMessage
    - sendDIDCommMessage
    - sendMessageDIDCommAlpha1
    - createVerifiablePresentation
    - createVerifiableCredential
    - createSelectiveDisclosureRequest
    - getVerifiableCredentialsForSdr
    - validatePresentationAgainstSdr
    # __TEMPLATE__: add your plugin methods here too. This assumes that your plugin is added to the agent. See below, toward the end of this config file.
    - myPluginFoo

# Database
dbConnection:
  $require: typeorm#DataSource
  $args:
    - type: sqlite
      database:
        $ref: /constants/databaseFile
      synchronize: false
      migrationsRun: true
      migrations:
        $require: '@veramo/data-store?t=object#migrations'
      logging: false
      entities:
        $require: '@veramo/data-store?t=object#Entities'

# Server configuration
server:
  baseUrl:
    $ref: /constants/baseUrl
  port:
    $ref: /constants/port
  use:
    # CORS
    - - $require: 'cors?t=function#default'

    # Add agent to the request object
    - - $require: '@veramo/remote-server?t=function#RequestWithAgentRouter'
        $args:
          - agent:
              $ref: /agent

    # DID Documents
    - - $require: '@veramo/remote-server?t=function#WebDidDocRouter'

    # API base path
    - - /messaging
      - $require: '@veramo/remote-server?t=function#MessagingRouter'
        $args:
          - metaData:
              type: DIDComm
              value: https

    # API base path
    - - /agent
      - $require: '@veramo/remote-server?t=function#apiKeyAuth'
        $args:
          # Please configure your own API key. This is used when executing agent methods through ${baseUrl}/agent or ${baseUrl}/api-docs
          - apiKey: test123
      - $require: '@veramo/remote-server?t=function#AgentRouter'
        $args:
          - exposedMethods:
              $ref: /constants/methods

    # Open API schema
    - - /open-api.json
      - $require: '@veramo/remote-server?t=function#ApiSchemaRouter'
        $args:
          - basePath: :3335/agent
            securityScheme: bearer
            apiName: Agent
            apiVersion: '1.0.0'
            exposedMethods:
              $ref: /constants/methods

    # Swagger docs
    - - /api-docs
      - $require: swagger-ui-express?t=object#serve
      - $require: swagger-ui-express?t=function#setup
        $args:
          - null
          - swaggerOptions:
              url: '/open-api.json'

  # Execute during server initialization
  init:
    - $require: '@veramo/remote-server?t=function#createDefaultDid'
      $args:
        - agent:
            $ref: /agent
          baseUrl:
            $ref: /constants/baseUrl
          messagingServiceEndpoint: /messaging

# Message handler plugin
messageHandler:
  $require: '@veramo/message-handler#MessageHandler'
  $args:
    - messageHandlers:
        # order matters
        - $require: '@veramo/did-comm#DIDCommMessageHandler'
        - $require: '@veramo/did-jwt#JwtMessageHandler'
        - $require: '@veramo/credential-w3c#W3cMessageHandler'
        - $require: '@veramo/selective-disclosure#SdrMessageHandler'

# DID resolvers
didResolver:
  $require: '@veramo/did-resolver#DIDResolverPlugin'
  $args:
    - resolver:
        $require: did-resolver#Resolver
        $args:
          - ethr:
              $ref: /ethr-did-resolver
            web:
              $ref: /web-did-resolver
            key:
              $ref: /did-key-resolver
            elem:
              $ref: /universal-resolver
            io:
              $ref: /universal-resolver
            ion:
              $ref: /universal-resolver
            sov:
              $ref: /universal-resolver

ethr-did-resolver:
  $require: ethr-did-resolver?t=function&p=/ethr#getResolver
  $args:
    - infuraProjectId: 5ffc47f65c4042ce847ef66a3fa70d4c

web-did-resolver:
  $require: web-did-resolver?t=function&p=/web#getResolver

universal-resolver:
  $require: '@veramo/did-resolver#UniversalResolver'
  $args:
    - url: https://dev.uniresolver.io/1.0/identifiers/

did-key-resolver:
  $require: '@veramo/did-provider-key?t=function&p=/key#getDidKeyResolver'

# Key Manager
keyManager:
  $require: '@veramo/key-manager#KeyManager'
  $args:
    - store:
        $require: '@veramo/data-store#KeyStore' # __TEMPLATE__: or you can use './build#MyKeyStore' instead
        $args:
          - $ref: /dbConnection
      kms:
        local:
          $require: '@veramo/kms-local#KeyManagementSystem'
          $args:
            - $require: '@veramo/data-store#PrivateKeyStore' # __TEMPLATE__: or you can use './build#MyPrivateKeyStore' instead
              $args:
                - $ref: /dbConnection
                - $require: '@veramo/kms-local#SecretBox'
                  $args:
                    - $ref: /constants/secretKey
        # __TEMPLATE__: you can install your own Key Management System implementation too
        my:
          $require: ./build#MyKeyManagementSystem

# DID Manager
didManager:
  $require: '@veramo/did-manager#DIDManager'
  $args:
    - store:
        $require: '@veramo/data-store#DIDStore' # __TEMPLATE__: or you can use './build#MyDIDStore'
        $args:
          - $ref: /dbConnection
      defaultProvider: did:ethr:goerli
      providers:
        # __TEMPLATE__: you can install your customized DID provider like so
        did:my:
          $require: ./build#MyIdentifierProvider
          $args:
            - defaultKms: local
        did:ethr:
          $require: '@veramo/did-provider-ethr#EthrDIDProvider'
          $args:
            - defaultKms: local
              network: mainnet
              rpcUrl: https://mainnet.infura.io/v3/5ffc47f65c4042ce847ef66a3fa70d4c
              gas: 1000001
              ttl: 31104001
        did:ethr:goerli:
          $require: '@veramo/did-provider-ethr#EthrDIDProvider'
          $args:
            - defaultKms: local
              network: goerli
              rpcUrl: https://goerli.infura.io/v3/5ffc47f65c4042ce847ef66a3fa70d4c
              gas: 1000001
              ttl: 31104001
        did:web:
          $require: '@veramo/did-provider-web#WebDIDProvider'
          $args:
            - defaultKms: local

# Agent
agent:
  $require: '@veramo/core#Agent'
  $args:
    - schemaValidation: false
      plugins:
        - $ref: /keyManager
        - $ref: /didManager
        - $ref: /didResolver
        - $ref: /messageHandler
        - $require: '@veramo/did-comm#DIDComm'
        - $require: '@veramo/credential-w3c#CredentialIssuer'
        - $require: '@veramo/selective-disclosure#SelectiveDisclosure'
        - $require: '@veramo/data-store#DataStore'
          $args:
            - $ref: /dbConnection
        - $require: '@veramo/data-store#DataStoreORM'
          $args:
            - $ref: /dbConnection
          # __TEMPLATE__: install your plugin on the `@veramo/cli` agent
        - $require: ./build#MyAgentPlugin
jaycoolslm commented 4 months ago

Shouldn't be different from what I cloned from repo, besides cars -> cors?t=function#default

dennisn00 commented 4 months ago

If you change the line $require: ./build#MyKeyManagementSystem to $require: ./build/agent-plugin/my-key-management-system.js#MyAgentPlugin, does that change the error? I would expect a similar error message but with a different file (other than MyKeyManagementSystem)

jaycoolslm commented 4 months ago

Error creating /Users/jaycool/code/veramo/veramo-plugin/build/agent-plugin/my-key-management-system.js['MyAgentPlugin']: Cannot find module '/Users/jaycool/code/veramo/veramo-plugin/build/agent-plugin/my-key-management-system.js' imported from /Users/jaycool/code/veramo/veramo-plugin/node_modules/@veramo/cli/build/lib/objectCreator.js. While creating object from pointer: /keyManager. While creating object from pointer: /agent. While creating object from pointer: /server

I get the equivalent when trying $require: ./build/agent-plugin/my-key-management-system.js#MyKeyManagementSystem

Im a bit confused though - are you able to clone fresh, and run e2e as per the docs successfully?

dennisn00 commented 4 months ago

So the original error seems to be fixed with the change. You just need to do the same thing again for MyAgentPlugin. So replace ./build#... with ./build/agent-plugin/my-agent-plugin.js#... for the import of MyAgentPlugin (and then for all other imports where this error pops up).

are you able to clone fresh, and run e2e as per the docs successfully?

After changing all the imports as above, yes, I was able to run it successfully

jaycoolslm commented 4 months ago

Are you a contributor to the project? would be useful if the agent.yml was correct as these bugs are not very intuitive to fix

jaycoolslm commented 4 months ago

I can raise a PR as well

jaycoolslm commented 4 months ago

So the original error seems to be fixed with the change. You just need to do the same thing again for MyAgentPlugin. So replace ./build#... with ./build/agent-plugin/my-agent-plugin.js#... for the import of MyAgentPlugin (and then for all other imports where this error pops up).

are you able to clone fresh, and run e2e as per the docs successfully?

After changing all the imports as above, yes, I was able to run it successfully

In your example you did my-key-management-system.ts#MyAgentPlugin require. Is this correct, or did you mean my-key-management-system.ts#MyKeyManagementSystem?

dennisn00 commented 4 months ago

This should be correct for the MyKeyManagementSystem: my-key-management-system.js#MyKeyManagementSystem (notice the .js instead of .ts). And just do the same for each line that starts with $require: ./build but replace with the correct .js file of course. I am not a contributor and also not an expert on Node, so I am not sure whether this is really the preferred solution. It's just a fix that worked for me.

jaycoolslm commented 4 months ago

Lol good spot on the .ts haha that was just muscle memory on my side

jaycoolslm commented 4 months ago

Cool that fixed it for me. Thanks for your help

jaycoolslm commented 4 months ago

@nickreynolds we can close this now