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

JSON-LD Context Merging? #271

Open
lautarodragan opened this issue Jul 1, 2019 · 0 comments
Open

JSON-LD Context Merging? #271

lautarodragan opened this issue Jul 1, 2019 · 0 comments

Comments

@lautarodragan
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant