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

Cannot read property 'did' of undefined. #21

Closed
ChinmayPatel opened this issue Aug 4, 2020 · 5 comments
Closed

Cannot read property 'did' of undefined. #21

ChinmayPatel opened this issue Aug 4, 2020 · 5 comments

Comments

@ChinmayPatel
Copy link

Trying to validate a signed credential, using the code below,

const emailAddressSignedCredential = '{"@context":[{"id":"@id","type":"@type","cred":"https://w3id.org/credentials#","schema":"http://schema.org/","dc":"http://purl.org/dc/terms/","xsd":"http://www.w3.org/2001/XMLSchema#","sec":"https://w3id.org/security#","Credential":"cred:Credential","issuer":{"@id":"cred:issuer","@type":"@id"},"issued":{"@id":"cred:issued","@type":"xsd:dateTime"},"claim":{"@id":"cred:claim","@type":"@id"},"credential":{"@id":"cred:credential","@type":"@id"},"expires":{"@id":"sec:expiration","@type":"xsd:dateTime"},"proof":{"@id":"sec:proof","@type":"@id"},"EcdsaKoblitzSignature2016":"sec:EcdsaKoblitzSignature2016","created":{"@id":"dc:created","@type":"xsd:dateTime"},"creator":{"@id":"dc:creator","@type":"@id"},"domain":"sec:domain","nonce":"sec:nonce","signatureValue":"sec:signatureValue"},{"ProofOfEmailCredential":"https://identity.jolocom.com/terms/ProofOfEmailCredential","schema":"http://schema.org/","email":"schema:email"}],"id":"claimId:3ddfa760e8c02745","issuer":"did:jolo:0e2abe7919a330e13e8c9cac2ef31a52a307880d6fd22e3878de4a6fc7c38f41","issued":"2020-08-03T17:54:44.752Z","type":["Credential","ProofOfEmailCredential"],"expires":"2021-08-03T17:54:44.749Z","proof":{"created":"2020-08-03T17:54:44.751Z","type":"EcdsaKoblitzSignature2016","nonce":"754a9373838c0a6e","signatureValue":"08ba912396a60e51f092a09e91fc0d89e07bc3c99140ca9e5c72b4258ec200e34bcaa8d4c0c0313916fe6481f259b73f8ae6eef49aac946c272a30ced451f991","creator":"did:jolo:0e2abe7919a330e13e8c9cac2ef31a52a307880d6fd22e3878de4a6fc7c38f41#keys-1"},"claim":{"email":"[email protected]","id":"did:jolo:0e2abe7919a330e13e8c9cac2ef31a52a307880d6fd22e3878de4a6fc7c38f41"},"name":"Email address"}';

const receivedCredential = JolocomLib.parse.signedCredential(emailAddressSignedCredential);

... and It's giving me the error below.

TypeError: Cannot read property 'did' of undefined
    at Object.exports.validateDigestable (/Users/chinmay/coding/keyko/ssi/server-identity/node_modules/jolocom-lib/ts/utils/validation.ts:21:62)
    at _callee2$ (/Users/chinmay/coding/keyko/ssi/server-identity/index.js:87:41)
    at tryCatch (/Users/chinmay/coding/keyko/ssi/server-identity/node_modules/babel-polyfill/node_modules/regenerator-runtime/runtime.js:65:40)
    at Generator.invoke [as _invoke] (/Users/chinmay/coding/keyko/ssi/server-identity/node_modules/babel-polyfill/node_modules/regenerator-runtime/runtime.js:303:22)
    at Generator.prototype.(anonymous function) [as next] (/Users/chinmay/coding/keyko/ssi/server-identity/node_modules/babel-polyfill/node_modules/regenerator-runtime/runtime.js:117:21)
    at step (/Users/chinmay/coding/keyko/ssi/server-identity/index.js:158:191)
    at /Users/chinmay/coding/keyko/ssi/server-identity/index.js:158:361

I've also attempted, fromJSON function by passing the object directly but it still didn't work. This approach gave me an error _jolocomLib.JolocomLib.parse.signedCredential.fromJSON is not a function.

Also, if you are wondering, emailAddressSignedCredential is created using the code below,

emailAddressSignedCredential = await userWallet.create.signedCredential({
      metadata: claimsMetadata.emailAddress,
      claim: { email: process.env.user_email },
      subject: userWallet.did // Our own DID, referred to as a self-issued credential
    }, process.env.user_secret)

Is this the library error or am I not using the library correctly?

@ChinmayPatel
Copy link
Author

Also, one more question. How can I view the public claim?

@mnzaki
Copy link
Contributor

mnzaki commented Aug 4, 2020

JolocomLib.parse.signedCredential is actually just a convenience wrapper around SignedCredential.fromJSON (it is the fromJSON static method). It expects a JSON objects (not stringify()ed!)
I hope you are using typescript, because you can avoid these kinds of errors entirely (the tsserver will point this kind of type mismatch out)

Re: public claim, there is no "public claim", these credentials are created and signed and passed around locally, not registered publicly anywhere.

There is though one credential which we typically store on IPFS, and that's the PublicProfile credential, which is meant to be used as a public profile for "service backend identities". This contains things like a URL and description and image.

@ChinmayPatel
Copy link
Author

I agree with the "public claim" question. That was my misunderstanding of the create function. I red the docs further and found out last night. Thanks for the clarification though.

Regarding JolocomLib.parse.signedCredential, the wrapper makes sense. My first attempt, after reading the doc was to attempt just that. I passed the JSON object created using userWallet.create.signedCredential directly to JolocomLib.parse.signedCredential and I receive an error below.


{ jsonld.SyntaxError: Invalid JSON-LD syntax; @context must be an object.
    at api.process (/Users/chinmay/coding/keyko/ssi/server-identity/node_modules/jsonld/lib/context.js:160:13)
    at contextsToProcess.forEach.localCtx (/Users/chinmay/coding/keyko/ssi/server-identity/node_modules/jsonld/lib/jsonld.js:328:17)
    at Array.forEach (<anonymous>)
    at /Users/chinmay/coding/keyko/ssi/server-identity/node_modules/jsonld/lib/jsonld.js:327:21
    at process._tickCallback (internal/process/next_tick.js:68:7)
  name: 'jsonld.SyntaxError',
  details: { code: 'invalid local context', context: undefined } }

@mnzaki
Copy link
Contributor

mnzaki commented Aug 4, 2020

you need to do something like:

const reparsed = JolocomLib.parse.signedCredential(emailAddressSignedCredential.toJSON())

@ChinmayPatel
Copy link
Author

Gotcha. I was trying all in one script and that created the confusion.

I've create a PR(jolocom/jolocom-lib#418) for the documentation update from other people running into the same issue. You are welcome to accept or reject it based on your plan ahead.

Thanks for the help.

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