Skip to content

advice on what to do when encountering @protected terms (vcdm/as2) #424

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

Closed
gobengo opened this issue Jan 1, 2024 · 5 comments
Closed

advice on what to do when encountering @protected terms (vcdm/as2) #424

gobengo opened this issue Jan 1, 2024 · 5 comments

Comments

@gobengo
Copy link

gobengo commented Jan 1, 2024

Take this example JSON-LD.
it appears to be erroneous do to the mediaType property being protected in the outer context, and trying to be redefined in the inner context

The outer context from "https://www.w3.org/ns/credentials/v2" defines a mediaType term as @protected and with a different IRI as the context inside the credentialSubject which is ActivityStreams2.

If possible, I'd love for the JSON serialization of the credentialSubject.icon.mediaType to map to https://www.w3.org/ns/activitystreams#mediaType but still use the JSON key mediaType.

This is the first time I've encountered @protected terms, so I'm trying to grok what my options are.

After tinkering around a bit, I think it might not be possible to do what I want.
(so, for now, when I try to make this JSON-LD, I compact the credentialSubject with a context like { "as": "https://www.w3.org/ns/activitystreams#" }, but then of course I lose credentialSubject.icon.mediaType and get credentialSubject.icon["as:mediaType"].

I also tried to insert a null in the credentialSubject["@context"] array, but I think that isn't allowed at least by jsonld.js (which I assume is pretty faithful to the spec).

{
  "type": [
    "VerifiableCredential"
  ],
  "credentialSubject": {
    "@context": [
      "https://www.w3.org/ns/activitystreams"
    ],
    "type": [
      "Organization"
    ],
    "icon": {
      "type": "Link",
      "mediaType": "image/png"
    }
  },
  "@context": [
    "https://www.w3.org/ns/credentials/v2"
  ]
}
@Fak3
Copy link
Contributor

Fak3 commented Jan 2, 2024

Related to #361

@dlongley
Copy link
Contributor

dlongley commented Jan 2, 2024

Here is an option that is based off of Example 2 from the Activity Streams spec, which looks like this:

{
  "@context": {
     "@vocab": "https://www.w3.org/ns/activitystreams",
     "ext": "https://canine-extension.example/terms/",
     "@language": "en"
  },
  "summary": "A note",
  "type": "Note",
  "content": "My dog has fleas.",
  "ext:nose": 0,
  "ext:smell": "terrible"
}

You can do this:

{
  "@context": [
    "https://www.w3.org/ns/credentials/v2",
    {
      "@vocab": "https://www.w3.org/ns/activitystreams#",
      "icon": {
        "@id": "https://www.w3.org/ns/activitystreams#icon",
        "@type": "@id",
        "@context": {
          "mediaType": "https://www.w3.org/ns/activitystreams#mediaType"
        }
      }
    }
  ],
  "type": [
    "VerifiableCredential"
  ],
  "credentialSubject": {
    "type": [
      "Organization"
    ],
    "icon": {
      "type": "Link",
      "mediaType": "image/png"
    }
  }
}

Playground link: http://tinyurl.com/yvhnf7vr

Note that protected terms can only be overridden when a new term definition is provided with a scoped context -- such that the terms being overridden will be scoped to that new term only. This ensures that consumers can have confidence in the definitions being used based on the structure of the JSON tree.

If you wanted to bring in the entire AS context you could also do so using @import, but there's currently a bug with the playground that disallows it because it thinks that the @vocab keyword itself (from the AS context) is being redefined (and you can't ever redefine keywords). Once fixed this should also work:

{
  "@context": [
    "https://www.w3.org/ns/credentials/v2",
    {
      "@import": "https://www.w3.org/ns/activitystreams",
      "mediaType": {
        "@id": "https://schema.org/encodingFormat"
      },
      "icon": {
        "@id": "https://www.w3.org/ns/activitystreams#icon",
        "@type": "@id",
        "@context": {
          "mediaType": "https://www.w3.org/ns/activitystreams#mediaType"
        }
      }
    }
  ],
  "type": [
    "VerifiableCredential"
  ],
  "credentialSubject": {
    "type": [
      "Organization"
    ],
    "icon": {
      "type": "Link",
      "mediaType": "image/png"
    }
  }
}

http://tinyurl.com/33fyyeuf

This approach does an "inline edit" of the AS v2 context via the @import feature to fix up the offending definition (mediaType) and adds the AS alternative definition for it when it is nested within icon.

So there should be a few options here to cause the output to behave properly. Ideally, I think, someone would construct a more modern activity streams context that uses scoped contexts to isolate definitions for usage with other documents types such as VCs. Alternatively, @vocab could be relied on as in the first working example here.

@gobengo
Copy link
Author

gobengo commented Jan 3, 2024

@dlongley Thank you, Dave. This looks extremely helpful. I did see in spec text that there may be an affordance for this, but couldn't figure it out in the playground. Sounds like maybe I didn't do the right incantation. Will try it out and get back to you here. tysm!

@davidlehn
Copy link
Contributor

Another possible path is to define a property with a scoped context and use that in credentialSubject. Shown here with an inline context, but this could be put in a small https://www.w3.org/ns/activitystreams-vc context if the only use of AS properties is under the special property. I think the output n-quads are what one would expect. There may be some variations of this.

{
  "@context": [
    "https://www.w3.org/ns/credentials/v2",
    {
      "BIKESHED": {
        "@id": "https://www.w3.org/ns/activitystreams#credential",
        "@type": "@id",
        "@context": "https://www.w3.org/ns/activitystreams"
      }
    }
  ],
  "type": [
    "VerifiableCredential"
  ],
  "credentialSubject": {
    "BIKESHED": {
      "type": [
        "Organization"
      ],
      "name": "imaorg",
      "icon": {
        "type": "Link",
        "mediaType": "image/png"
      }
    }
  }
}

https://tinyurl.com/253tu643

Pros:

  • Can be made short and minimal compared to alternatives.
  • Skips the tricky overrides.

Cons:

  • Needs extra setup.
  • Needs a special top-level property.

@gobengo
Copy link
Author

gobengo commented Feb 27, 2024

I have the advice I was originally looking for now. tysm all

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

4 participants