hyperledger-archives / aries-framework-go

Hyperledger Aries Framework Go provides packages for building Agent / DIDComm services.
https://wiki.hyperledger.org/display/ARIES/aries-framework-go
Apache License 2.0
238 stars 159 forks source link

Error: Dereferencing a URL did not result in a valid JSON-LD context #2853

Open Vid201 opened 3 years ago

Vid201 commented 3 years ago

What I'm trying to do

Sign verifiable credential.

Expected result

Signed verifiable credential.

Actual result

{"code":6011,"message":"parse vc : compact JSON-LD document: loading remote context failed: Dereferencing a URL did not result in a valid JSON-LD context: https://www.w3.org/2018/credentials/examples/v1"}

Sample code / test case

curl -k -X POST "https://localhost:8082/verifiable/signcredential" -H "accept:application/json" -H "Content-Type:application/json" -d "{\"created\":\"2021-05-05T10:22:25.999Z\",\"credential\":{\"@context\":[\"https://www.w3.org/2018/credentials/v1\",\"https://www.w3.org/2018/credentials/examples/v1\"],\"credentialSubject\":{\"id\":\"sample-credential-subject-id\"},\"id\":\"http://example.edu/credentials/1872\",\"issuanceDate\":\"2010-01-01T19:23:24Z\",\"issuer\":{\"id\":\"did:example:09s12ec712ebc6f1c671ebfeb1f\",\"name\":\"ExampleUniversity\"},\"referenceNumber\":83294847,\"type\":[\"VerifiableCredential\",\"UniversityDegreeCredential\"]},\"did\":\"did:key:z6Mkf3mSeHmehoXVdXQt1uNimKxD9RqFXHS6EgbVaDx4B5Z5\",\"signatureType\":\"Ed25519Signature2018\"}"

Note: this was working in previous versions (working on commit 2a52bb79077635cffd69021d403a8cdfc3149fe8).

aholovko commented 3 years ago

Hi @Vid201,

We have updated the way how JSON-LD contexts are handled by the framework - now contexts are not fetched from the remote sources by default. This is mainly because of performance considerations and for having more control over what external calls are made by the framework.

There is a core set of contexts that the framework embeds, and https://www.w3.org/2018/credentials/examples/v1 is not there.

Depending on how you are using the framework, there are several ways how you can add support for additional contexts.

  1. If you have access to the framework instance, you can initialize it with the custom loader - either the one with needed contexts or the one that enables remote fetching:

    • Check this example on how to create a custom loader with extra contexts and initialize the framework with it
    • For enabling remote fetching (contexts, that are not in a core set, will be resolved from the network), you can use the following code when creating a custom loader:
      loader, err := jsonld.NewDocumentLoader(dbProvider,
      jsonld.WithRemoteDocumentLoader(ld.NewDefaultDocumentLoader(http.DefaultClient)))
  2. You can also add needed contexts thru API, here is an example with JS API.

Vid201 commented 3 years ago

Cool, thanks for the detailed explanation.