Skip to content

JSON-LD Context Merging? #271

@lautarodragan

Description

@lautarodragan

We're currently merging three different JSON-LD contexts in configureCreateVerifiableClaim: the default one, the one associated with the claim type, and the user-provided one.

export const configureCreateVerifiableClaim = ({
issuer,
type = ClaimType.Work,
context = {},
}: CreateVerifiableClaimConfig) => async (claim: Claim): Promise<VerifiableClaim> => {
const verifiableClaim = {
'@context': { ...DefaultClaimContext, ...claimTypeDefaults[type], ...context },
type,
issuer,
issuanceDate: new Date().toISOString(),
claim,
}
const id = await generateClaimId(verifiableClaim)
return { ...verifiableClaim, id }
}

These are the contexts used to sign and serialize the whole VerifiableClaim structure, of which what we call a claim is a child object.

export const DefaultClaimContext: ClaimContext = {
cred: 'https://w3id.org/credentials#',
dc: 'http://purl.org/dc/terms/',
schema: 'http://schema.org/',
sec: 'https://w3id.org/security#',
id: 'sec:digestValue',
issuer: 'cred:issuer',
issuanceDate: 'cred:issued',
type: 'schema:additionalType',
claim: 'schema:Thing', // The most generic definition in schema.org,
}

The issue is that we're listing domain-specific fields that belong inside the claim immediately inside the verifiable claim:

export const DefaultWorkClaimContext: ClaimContext = {
archiveUrl: 'schema:url',
author: 'schema:author',
canonicalUrl: 'schema:url',
claim: 'schema:CreativeWork',
contributors: {
'@id': 'schema:ItemList',
'@container': '@list',
'@type': 'schema:contributor',
},
copyrightHolder: 'schema:copyrightHolder',
dateCreated: 'schema:dateCreated',
datePublished: 'schema:datePublished',
license: 'schema:license',
name: 'schema:name',
tags: 'schema:keywords',
hash: 'sec:digestValue',
}

This leads to the following: taking a look at this claim, for example:

{
  "@context": {
    "cred": "https:\/\/w3id.org\/credentials#",
    "dc": "http:\/\/purl.org\/dc\/terms\/",
    "schema": "http:\/\/schema.org\/",
    "sec": "https:\/\/w3id.org\/security#",
    "id": "sec:digestValue",
    "issuer": "cred:issuer",
    "issuanceDate": "cred:issued",
    "type": "schema:additionalType",
    "claim": "schema:CreativeWork",
    "archiveUrl": "schema:url",
    "author": "schema:author",
    "canonicalUrl": "schema:url",
    "contributors": {
      "@id": "schema:ItemList",
      "@container": "@list",
      "@type": "schema:contributor"
    },
    "copyrightHolder": "schema:copyrightHolder",
    "dateCreated": "schema:dateCreated",
    "datePublished": "schema:datePublished",
    "license": "schema:license",
    "name": "schema:name",
    "tags": "schema:keywords",
    "hash": "sec:digestValue",
    "content": "schema:text",
    "creator": "schema:creator",
    "genre": "schema:genre",
    "duration": "schema:duration"
  },
  "id": "2c38ab28213532b49eb03b971dd32039900acba918db28902e3fe40b271b94bb",
  "type": "Work",
  "issuer": "data:;base64,eyJhbGdvcml0aG0iOiJFZDI1NTE5U2lnbmF0dXJlMjAxOCIsInB1YmxpY0tleSI6IkU4YkJ3cnNtSFVRYU1QcFE4NUR0VXQ5S01FNUZuR3dONmdrU1IzOVE1TWZEIn0=",
  "issuanceDate": "2019-06-25T09:18:09.452Z",
  "claim": {
    "archiveUrl": "https:\/\/ipfs.poetnetwork.net\/ipfs\/QmanrB6yaVSD7yL6T5C921nBDRkhyfMdhufBhVZwMzNUf4",
    "hash": "QmanrB6yaVSD7yL6T5C921nBDRkhyfMdhufBhVZwMzNUf4",
    "name": "Astronomy Domine",
    "datePublished": "2019-06-25T09:14:35.091Z",
    "dateCreated": "2019-06-25T09:14:35.091Z",
    "author": "Pink Floyd",
    "tags": "",
    "creator": "Syd Barrett",
    "genre": "Space Rock",
    "duration": "4:12"
  },
  "sec:proof": {
    "@graph": {
      "@type": "sec:Ed25519Signature2018",
      "dc:created": {
        "@type": "http:\/\/www.w3.org\/2001\/XMLSchema#dateTime",
        "@value": "2019-06-25T09:18:09Z"
      },
      "dc:creator": {
        "@id": "data:;base64,eyJhbGdvcml0aG0iOiJFZDI1NTE5U2lnbmF0dXJlMjAxOCIsInB1YmxpY0tleSI6IkU4YkJ3cnNtSFVRYU1QcFE4NUR0VXQ5S01FNUZuR3dONmdrU1IzOVE1TWZEIn0="
      },
      "sec:jws": "eyJhbGciOiJFZERTQSIsImI2NCI6ZmFsc2UsImNyaXQiOlsiYjY0Il19..dyQns2QnHuD7PUX77Yl3OhHYcalLxUyMsd0QyYML4wCY7xDg4sLGzzYICy1gcK0EtJGM8xQV3mJzHmeTH4s4Ag",
      "sec:nonce": "cjxblkgmu00000htie07oik49"
    }
  }
}

The archiveUrl is an immediate child of the root VerifiableClaim in the @context yet it's inside claim, which is defined as a schema:CreativeWork in the context.

This works right now. My guess is jsonld accepts fields defined in the matching element or anywhere in the context.

Q: Is this well-defined or accidental behaviour?

Either way, we'll probably want to vamp up the logic so the VerifiableClaim is a constant structure for all Po.et and the inner Claim is free form.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions