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

Agent method identityManagerAddService fails upon validation (daf-cli) #275

Closed
tscheckow opened this issue Nov 19, 2020 · 9 comments
Closed
Labels
bug Something isn't working

Comments

@tscheckow
Copy link

tscheckow commented Nov 19, 2020

Describe the bug
When I execute the method "identityManagerAddService" in the CLI with the following input:

Arguments:  {
  "did": "did:ethr:rinkeby:0x5af6029d1cb6cb3a49745cc6d1a9fa55d07e33ac",
  "options": {},
  "service": {
    "description": "Messaging Endpoint",
    "id": "did:ethr:rinkeby:0x5af6029d1cb6cb3a49745cc6d1a9fa55d07e33ac#msg",
    "serviceEndpoint": "http://localhost:3332",
    "type": "Messaging"
  }
}

I receive the following Error:

Expected type object but found type string; identityManagerAddService; #/; INVALID_TYPE; undefined.

I tried it with or without all optional fields.

If I try it with the CLI integrated function i get this:

martin@workhorse:~/Documents/daf-cli$ npx daf identity-manager -s
? Select DID did:ethr:rinkeby:0xb788d22dd494ee4b212443d492a130a1fc456e48
? Service type Messaging
? Endpoint http://localhost:3332
? ID did:ethr:rinkeby:0xb788d22dd494ee4b212443d492a130a1fc456e48#msg
{ PluginReturnTypeError: Expected type object but found type string; identityManagerAddService; #/; INVALID_TYPE; undefined
    at new PluginReturnTypeError (/usr/local/lib/node_modules/daf-cli/node_modules/daf-core/build/validator.js:41:28)
    at Object.exports.validateReturnType (/usr/local/lib/node_modules/daf-cli/node_modules/daf-core/build/validator.js:65:15)
    at Agent.<anonymous> (/usr/local/lib/node_modules/daf-cli/node_modules/daf-core/build/agent.js:233:41)
    at step (/usr/local/lib/node_modules/daf-cli/node_modules/daf-core/build/agent.js:44:23)
    at Object.next (/usr/local/lib/node_modules/daf-cli/node_modules/daf-core/build/agent.js:25:53)
    at fulfilled (/usr/local/lib/node_modules/daf-cli/node_modules/daf-core/build/agent.js:16:58)
  name: 'PluginReturnTypeError',
  method: 'identityManagerAddService',
  description: undefined,
  path: '#/',
  code: 'INVALID_TYPE' }

After any of the two actions above, I can no longer resolve the DID:

martin@workhorse:~/Documents/daf-cli$ npx daf resolve did:ethr:rinkeby:0xb788d22dd494ee4b212443d492a130a1fc456e48
Missing required property: id; resolveDid; #/service/0; OBJECT_MISSING_REQUIRED_PROPERTY; undefined

I suspect, the document gets somehow destroyed by the addService function. However, I can still look it up in the local database and it looks like this, if I use the command npx daf execute -m identityManagerAddKey -f messaging_service.json:

{                                                                                                                                                                                                            
  "did": "did:ethr:goerli:0x6272465e96d450f1efd5c25c89211e45308e18d1", 
  "provider": "did:ethr:goerli",
  "alias": "martin",
  "controllerKeyId": "047e4af26804a897f44ee1538c22c2043b1045f139db43c14bf87d73d83ebef2a3425234cdcb29bb5e0e42d3a40483d91bc384a7e81c4dfc8aa2e1ada5affbf4b7",
  "keys": [                                                                                                                                                                                                  
    {                                                                                                                                                                                                        
      "kid": "047e4af26804a897f44ee1538c22c2043b1045f139db43c14bf87d73d83ebef2a3425234cdcb29bb5e0e42d3a40483d91bc384a7e81c4dfc8aa2e1ada5affbf4b7", 
      "kms": "local",
      "type": "Secp256k1", 
      "publicKeyHex": "047e4af26804a897f44ee1538c22c2043b1045f139db43c14bf87d73d83ebef2a3425234cdcb29bb5e0e42d3a40483d91bc384a7e81c4dfc8aa2e1ada5affbf4b7",
      "privateKeyHex": "69e0cb7e68ae0120f2caacda77aa5ba35dac8bf5e41dc29cfd125de590d97172e318e80cf38edde798456818263a0415faa9875c371feb5ff8017efe363828cca4c71acb857bc17fa004b58ddca18c09db699fe5b87fa8dd79b0",
      "meta": null
    }
  ],
  "services": [
    {
      "id": "did:ethr:goerli:0x6272465e96d450f1efd5c25c89211e45308e18d1#msg",
      "type": "Messaging",
      "serviceEndpoint": "http://localhost:3332/messaging", 
      "description": "Messaging Endpoint"
    }
  ]
} 

If I use the CLI integrated function daf identity-manager -s it breaks the local database:

{ PluginReturnTypeError: Expected type object but found type string; identityManagerAddService; #/; INVALID_TYPE; undefined
    at new PluginReturnTypeError (/usr/local/lib/node_modules/daf-cli/node_modules/daf-core/build/validator.js:41:28)
    at Object.exports.validateReturnType (/usr/local/lib/node_modules/daf-cli/node_modules/daf-core/build/validator.js:65:15)
    at Agent.<anonymous> (/usr/local/lib/node_modules/daf-cli/node_modules/daf-core/build/agent.js:233:41)
    at step (/usr/local/lib/node_modules/daf-cli/node_modules/daf-core/build/agent.js:44:23)
    at Object.next (/usr/local/lib/node_modules/daf-cli/node_modules/daf-core/build/agent.js:25:53)
    at fulfilled (/usr/local/lib/node_modules/daf-cli/node_modules/daf-core/build/agent.js:16:58)
  name: 'PluginReturnTypeError',
  method: 'identityManagerAddService',
  description: undefined,
  path: '#/',
  code: 'INVALID_TYPE' }

To Reproduce
Steps to reproduce the behaviour:

  1. Create a DID on any testnet, add some funds and set a higher gas in agent.yml
  2. Try to add a messaging service to the DID either with npx daf identity-manager -s or with npx daf execute -m identityManagerAddService
  3. Try to resolve the DID after the failed adding of the messaging service with either method
  4. Try to explore data after using the command npx daf identity-manager -s

Expected behaviour
I expect a new messaging endpoint as service in the public DID document such that it is still resolvable. The CLI command daf identity-manager -s should not break the local database.

Versions (please complete the following information):

  • daf-cli: [7.0.0-beta.45]
@tscheckow tscheckow added the bug Something isn't working label Nov 19, 2020
@mirceanis
Copy link
Member

it looks like the same issue observed while working around #255

mirceanis added a commit that referenced this issue Nov 20, 2020
* add `schemaValidation` flag to `IAgentOptions` to enable validation of inputs and outputs.
* update config templates to set `schemaValidation` flag to false

Closes #255
Closes #275
mirceanis added a commit that referenced this issue Nov 20, 2020
* add `schemaValidation` flag to `IAgentOptions` to enable validation of inputs and outputs.
* update config templates to set `schemaValidation` flag to false

Closes #255
Closes #275
mirceanis added a commit that referenced this issue Nov 23, 2020
* add `schemaValidation` flag to `IAgentOptions` to enable validation of inputs and outputs.
* update config templates to set `schemaValidation` flag to false
* update integration tests to consider validation

Closes #255
Closes #275
mirceanis added a commit that referenced this issue Nov 23, 2020
* add `schemaValidation` flag to `IAgentOptions` to enable validation of inputs and outputs.
* update config templates to set `schemaValidation` flag to false
* update integration tests to consider validation

Closes #255
Closes #275
@mirceanis
Copy link
Member

@tscheckow can you try again using [daf-cli: 7.0.0-beta.47] and see if you make progress?

@tscheckow
Copy link
Author

@tscheckow can you try again using [daf-cli: 7.0.0-beta.47] and see if you make progress?

Thank you so much for delivering a (potential) fix so fast. I tried to install beta.47 using npm:

sudo npm i -g daf-cli@7.0.0-beta.47
npm ERR! code ETARGET
npm ERR! notarget No matching version found for daf-cli@7.0.0-beta.47.
npm ERR! notarget In most cases you or one of your dependencies are requesting
npm ERR! notarget a package version that doesn't exist.

Should I build it myself based on the last state of the beta repo or do you publish beta.47?

@mirceanis
Copy link
Member

It's probably my bad that the beta47 release is problematic. I'll relaunch today beta48.
In the meantime, you can try running from a local build of the beta branch to see if it works out.

@tscheckow
Copy link
Author

tscheckow commented Nov 24, 2020

I built it from source (beta branch):

martin@workhorse:~/git/daf-cli-test/daf-beta/packages/daf-cli/bin$ ./daf.js -v
7.0.0-beta.48

I still get the same error:

martin@workhorse:~/git/daf-cli-test/daf-beta/packages/daf-cli/bin$ ./daf.js identity-manager -s
? Select DID did:ethr:rinkeby:0xb297e829f7175144981f1b07154abeebc2466486
? Service type Messaging
? Endpoint http://localhost:3332/messaging
? ID did:ethr:rinkeby:0xb297e829f7175144981f1b07154abeebc2466486#msg
{ PluginReturnTypeError: Expected type object but found type string; identityManagerAddService; #/; INVALID_TYPE; undefined
    at new PluginReturnTypeError (/home/martin/git/daf-cli-test/daf-beta/packages/daf-core/build/validator.js:41:28)
    at Object.exports.validateReturnType (/home/martin/git/daf-cli-test/daf-beta/packages/daf-core/build/validator.js:65:15)
    at Agent.<anonymous> (/home/martin/git/daf-cli-test/daf-beta/packages/daf-core/build/agent.js:272:41)
    at step (/home/martin/git/daf-cli-test/daf-beta/packages/daf-core/build/agent.js:44:23)
    at Object.next (/home/martin/git/daf-cli-test/daf-beta/packages/daf-core/build/agent.js:25:53)
    at fulfilled (/home/martin/git/daf-cli-test/daf-beta/packages/daf-core/build/agent.js:16:58)
  name: 'PluginReturnTypeError',
  method: 'identityManagerAddService',
  description: undefined,
  path: '#/',
  code: 'INVALID_TYPE' }

@tscheckow
Copy link
Author

tscheckow commented Nov 24, 2020

However, if I use the method identityManagerAddService directly, it works:

martin@workhorse:~/Documents/daf-cli$ daf-beta48 execute -m identityManagerAddService -f messaging_service.json
{ argsFile: 'messaging_service.json' }

Method:  identityManagerAddService

Arguments:  {
  "did": "did:ethr:rinkeby:0xb297e829f7175144981f1b07154abeebc2466486",
  "service": {
    "id": "did:ethr:rinkeby:0xb297e829f7175144981f1b07154abeebc2466486#msg",
    "type": "Messaging",
    "description": "Handles incoming POST messages",
    "serviceEndpoint": "http://localhost:3332/messaging"
  }
}

Result : "0x001364d7c812fe96221232f376f16819c49e90688ee2a688d1d6f477418c7d2f"

The didDoc can be resolve without error:

martin@workhorse:~/Documents/daf-cli$ daf-beta48 resolve did:ethr:rinkeby:0xb297e829f7175144981f1b07154abeebc2466486
{ '@context': 'https://w3id.org/did/v1',
  id:
   'did:ethr:rinkeby:0xb297e829f7175144981f1b07154abeebc2466486',
  publicKey:
   [ { id:
        'did:ethr:rinkeby:0xb297e829f7175144981f1b07154abeebc2466486#controller',
       type: 'Secp256k1VerificationKey2018',
       controller:
        'did:ethr:rinkeby:0xb297e829f7175144981f1b07154abeebc2466486',
       ethereumAddress: '0xb297e829f7175144981f1b07154abeebc2466486' } ],
  authentication:
   [ { type: 'Secp256k1SignatureAuthentication2018',
       publicKey:
        'did:ethr:rinkeby:0xb297e829f7175144981f1b07154abeebc2466486#controller' } ],
  service:
   [ { type: 'Messaging',
       serviceEndpoint: 'http://localhost:3332/messaging' } ] }

@mirceanis
Copy link
Member

Apologies for the failed releases, you can try 7.0.0-beta.49 which should finally have all packages at the same version.

The workaround is a new flag in the agent constructor options which can toggle schema validation off.
Check your agent.yml file.

The default config now looks something like this:

#...
agent:
  $require: daf-core#Agent
  $args:
    - schemaValidation: true # set this to false to work around PluginReturnTypeError
      plugins:
        - $require: daf-key-manager#KeyManager
#...

@tscheckow
Copy link
Author

When setting schemaValidation to false, adding a service works as expected:

martin@workhorse:~/Documents/daf-cli$ daf-beta49 identity-manager -s
? Select DID did:ethr:rinkeby:0xd52591d784ac6c78a0d8e90be9c41238e6ad535c
? Service type Messaging
? Endpoint http://localhost:3332/messaging
? ID did:ethr:rinkeby:0xd52591d784ac6c78a0d8e90be9c41238e6ad535c#msg
Success: 0xc2a1968b11e69987a4e828d8b7b2d8535e37800c3a26cce54ef004cf47a0cf32

Resolving and looking the did up in the local database using data-explorer works too. I will upgrade my issuer and verifier components to beta49. Is there any recommended updating procedure? Thank you very much for everything.

mirceanis added a commit that referenced this issue Nov 24, 2020
mirceanis added a commit that referenced this issue Nov 24, 2020
@mirceanis
Copy link
Member

Ok, default CLI config will start with schemaValidation set to false.
This will be available in the next beta release, so I'm closing this now.

Thank you for reporting

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants