digitalbazaar / jsonld.js

A JSON-LD Processor and API implementation in JavaScript
https://json-ld.org/
Other
1.66k stars 195 forks source link

Word retrieved for other context? #450

Closed lemoustachiste closed 3 years ago

lemoustachiste commented 3 years ago

Hi,

I'm trying to add a property to a context, named display. When it named as such, the property is actually dereferenced from https://www.w3.org/ns/odrl/2/ rather than my own context.

The way I'm defining it is:

"@context": {
  "bc": "https://w3id.org/blockcerts#",
  "display": {
      "@id": "bc:display",
      "@context": {
        "id": "@id",
        "type": "@type",
        "contentMediaType": {"@id": "bc:contentMediaType", "@type": "@id"},
        "contentEncoding": {"@id": "bc:contentEncoding", "@type": "@id"},
        "content": {"@id": "bc:content", "@type": "@id"}
      }
    }
}

For my own knowledge, why is it that I'm defining wrong here?

davidlehn commented 3 years ago

It's a bit unclear what the issue is. Do you have a minimal full example that shows the problem? The tools won't just randomly use that odrl link, so it's coming from somewhere.

lemoustachiste commented 3 years ago

it's not too straightfoward to test at this moment, as I am pointing to a local server. Here is the file that's passed to jsonld:

{
  "@context": [
    "https://www.w3.org/2018/credentials/v1",
    "http://127.0.0.1:8000/context.json",
    "https://www.w3.org/2018/credentials/examples/v1"
  ],
  "id": "urn:uuid:bbba8553-8ec1-445f-82c9-a57251dd731c",
  "type": [
    "VerifiableCredential",
    "BlockcertsCredential"
  ],
  "issuer": "https://blockcerts.learningmachine.com/issuer/5a4fe9931f607f0f3452a65e.json",
  "issuanceDate": "2010-01-01T19:33:24Z",
  "credentialSubject": {
    "id": "did:example:ebfeb1f712ebc6f1c276e12ec21",
    "alumniOf": {
      "id": "did:example:c276e12ec21ebfeb1f712ebc6f1"
    }
  },
  "metadata": {
    "classOf": "2021"
  },
  "display": {
    "contentMediaType": "text/html",
    "content": "<html><body><h1>Some content</h1></body></html>"
  },
  "proof": {
    "type": "MerkleProof2019",
    "created": "2021-04-13T16:59:23.819506",
    "proofValue": "zMcm4LfQFUZkWZxsqphMu6UmCT2Mj7evnkRWxC5t8HfiDTM1S45sy6AGHcwFdoT6UnzK7he83vg1Ht7fAp8EB3Sp6Amta8F63mWFLsz2f3PUcD8mZ77QeeNrBrP35bwphq33kfuU8Ht89Ckv3s2ZbGcSg5bgvjzBYQwN97UCD1pzLv9ogMErcrKwi5VFbUiZb5YtfMzknkMVFgPKsQC43zLb1n7PdyxoxnBHpUK2Y482RwfLbSSEb96DEQneXGJ4YQ9JgSKupBFSf6nWVkFfRPAzdyggfJcb6Y8bybpEuP6HftB6XZc",
    "proofPurpose": "assertionMethod",
    "verificationMethod": "did:example:23adb1f712ebc6f1c276eba4dfa#key-1"
  }
}

And the context:

{
  "@context": {
    "id": "@id",
    "type": "@type",
    "bc": "https://w3id.org/blockcerts#",
    "cp": "https://w3id.org/chainpoint#",
    "vc": "https://www.w3.org/2018/credentials/v1",
    "schema": "https://schema.org/",
    "sec": "https://w3id.org/security#",
    "xsd": "http://www.w3.org/2001/XMLSchema#",

    "MerkleProof2019": "sec:MerkleProof2019",

    "BlockcertsCredential": "bc:BlockcertsCredential",
    "introductionUrl": { "@id": "bc:introductionUrl", "@type": "@id" },
    "metadata": "bc:metadata",
    "display": {
      "@id": "bc:display",
      "@context": {
        "id": "@id",
        "type": "@type",
        "contentMediaType": {"@id": "bc:contentMediaType", "@type": "@id"},
        "contentEncoding": {"@id": "bc:contentEncoding", "@type": "@id"},
        "content": {"@id": "bc:content", "@type": "@id"}
      }
    },

    "CryptographicKey": "sec:Key",

    "domain": "sec:domain",
    "nonce": "sec:nonce",
    "proofValue": "sec:proofValue",
    "assertionMethod": {"@id": "sec:assertionMethod", "@type": "@id", "@container": "@set"},
    "authentication": {"@id": "sec:authenticationMethod", "@type": "@id", "@container": "@set"},
    "proofPurpose": {"@id": "sec:proofPurpose", "@type": "@vocab"},
    "verificationMethod": {"@id": "sec:verificationMethod", "@type": "@id"},
    "created": {"@id": "https://purl.org/dc/terms/created", "@type": "xsd:dateTime"},
    "challenge": "sec:challenge",
    "expires": {"@id": "sec:expiration", "@type": "xsd:dateTime"},

    "name": {
      "@id": "schema:name"
    }
  }
}

I am using a simple python server for this, but in real world usage I'm actually caching the context for the localhost url and passing it to the documentLoader property.

We are still using jsonld 1.8.1 because haven't had the opportunity to spend the time changing for older versions. Let me know if that's not enough, I appreciate your support.

thanks

dmitrizagidulin commented 3 years ago

Hi @lemoustachiste. The odrl reference is coming from the Example VC context (https://www.w3.org/2018/credentials/examples/v1), and it has a display property defined, that's colliding with your definition. So, you have a couple of options:

lemoustachiste commented 3 years ago

FWIW, this is the dereferenced output:

<did:example:ebfeb1f712ebc6f1c276e12ec21> <http://schema.org/alumniOf> <did:example:c276e12ec21ebfeb1f712ebc6f1> .
<urn:uuid:bbba8553-8ec1-445f-82c9-a57251dd731c> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <https://w3id.org/blockcerts#BlockcertsCredential> .
<urn:uuid:bbba8553-8ec1-445f-82c9-a57251dd731c> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <https://www.w3.org/2018/credentials#VerifiableCredential> .
<urn:uuid:bbba8553-8ec1-445f-82c9-a57251dd731c> <http://www.w3.org/ns/odrl/2/display> _:c14n0 .
<urn:uuid:bbba8553-8ec1-445f-82c9-a57251dd731c> <https://w3id.org/blockcerts#metadata> _:c14n1 .
<urn:uuid:bbba8553-8ec1-445f-82c9-a57251dd731c> <https://www.w3.org/2018/credentials#credentialSubject> <did:example:ebfeb1f712ebc6f1c276e12ec21> .
<urn:uuid:bbba8553-8ec1-445f-82c9-a57251dd731c> <https://www.w3.org/2018/credentials#issuanceDate> "2010-01-01T19:33:24Z"^^<http://www.w3.org/2001/XMLSchema#dateTime> .
<urn:uuid:bbba8553-8ec1-445f-82c9-a57251dd731c> <https://www.w3.org/2018/credentials#issuer> <https://blockcerts.learningmachine.com/issuer/5a4fe9931f607f0f3452a65e.json> .
_:c14n0 <http://fallback.org/content> "<html><body><h1>Some content</h1></body></html>" .
_:c14n0 <http://fallback.org/contentMediaType> "text/html" .

You'll notice the displayissue: <urn:uuid:bbba8553-8ec1-445f-82c9-a57251dd731c> <http://www.w3.org/ns/odrl/2/display> _:c14n0 .

lemoustachiste commented 3 years ago

@dmitrizagidulin Thanks, I missed your answer (no notification). I'll try with the proposed approached then. Thanks

lemoustachiste commented 3 years ago

@dmitrizagidulin's answer solved my problem.

Thanks again