Open-Attestation / open-attestation

Meta framework for providing digital provenance and integrity to documents.
https://openattestation.com
Apache License 2.0
54 stars 18 forks source link

BUG: "The property openAttestationMetadata in the input was not defined in the context" #201

Closed Neketek closed 3 years ago

Neketek commented 3 years ago

Hi.

So, I'm trying to wrap the document

{
  "version": "https://schema.openattestation.com/3.0/schema.json",
  "@context": [
    "https://www.w3.org/2018/credentials/v1",
    "https://schemata.openattestation.com/com/openattestation/1.0/DrivingLicenceCredential.json",
    "https://schemata.openattestation.com/com/openattestation/1.0/OpenAttestation.v3.json",
    "https://schemata.openattestation.com/com/openattestation/1.0/CustomContext.json"
  ],
  "reference": "SERIAL_NUMBER_123",
  "name": "Republic of Singapore Driving Licence",
  "issuanceDate": "2010-01-01T19:23:24Z",
  "validFrom": "2010-01-01T19:23:24Z",
  "issuer": {
    "id": "https://example.com",
    "name": "DEMO STORE"
  },
  "type": [
    "VerifiableCredential",
    "DrivingLicenceCredential"
  ],
  "credentialSubject": {
    "id": "did:example:SERIAL_NUMBER_123",
    "class": [
      {
        "type": "3",
        "effectiveDate": "2010-01-01T19:23:24Z"
      },
      {
        "type": "3A",
        "effectiveDate": "2010-01-01T19:23:24Z"
      }
    ]
  },
  "openAttestationMetadata": {
    "template": {
      "name": "CUSTOM_TEMPLATE",
      "type": "EMBEDDED_RENDERER",
      "url": "https://localhost:3000/renderer"
    },
    "proof": {
      "type": "OpenAttestationProofMethod",
      "method": "DID",
      "value": "did:ethr:0xE712878f6E8d5d4F9e87E10DA604F9cB564C9a89",
      "revocation": {
        "type": "REVOCATION_STORE",
        "location": "$DOCUMENT_STORE_ADDRESS"
      }
    },
    "identityProof": {
      "type": "DID",
      "identifier": "did:ethr:0xE712878f6E8d5d4F9e87E10DA604F9cB564C9a89"
    }
  }
}

But I get

    "The property openAttestationMetadata in the input was not defined in the context"

      at expansionMap (node_modules/@govtechsg/open-attestation/dist/cjs/3.0/validate/validate.js:149:43)
      at _expandObject (node_modules/jsonld/lib/expand.js:445:26)
      at Object.<anonymous>.api.expand (node_modules/jsonld/lib/expand.js:248:3)
      at Function.jsonld.expand (node_modules/jsonld/lib/jsonld.js:325:18)

package.json

{
  "name": "ts-document-store-worker",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "build": "webpack build --progress --color",
    "test": "jest --detectOpenHandles -i --collect-coverage"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@types/jest": "^24.9.1",
    "@types/node": "^16.7.1",
    "jest": "^24.9.0",
    "ts-jest": "^24.3.0",
    "ts-loader": "^9.2.5",
    "typescript": "^4.3.5",
    "webpack": "^5.51.1",
    "webpack-cli": "^4.8.0"
  },
  "dependencies": {
    "@govtechsg/document-store": "^2.2.1",
    "@govtechsg/oa-verify": "^7.5.0",
    "@govtechsg/open-attestation": "^6.0.2",
    "@sentry/node": "^6.11.0",
    "@types/lodash": "^4.14.172",
    "@types/triple-beam": "^1.3.2",
    "aws-sdk": "^2.975.0",
    "ethers": "^5.4.5",
    "lodash": "^4.17.21",
    "triple-beam": "^1.3.0",
    "web3": "^1.5.2",
    "winston": "^3.3.3",
    "winston-transport": "^4.4.0",
    "winston-transport-sentry-node": "^1.0.2"
  }
}

I've checked the document using cli, but I get the same result. Probably the problem is somehow related to the context definitions. You probably know better.

Fak3 commented 3 years ago

Add type "OpenAttestationCredential" to the top-level object

Neketek commented 3 years ago

@Fak3 Thanks, fixed the problem, I've got the example from here, so maybe you want to address the missing type there. https://github.com/Open-Attestation/oa-verify/blob/master/test/fixtures/v3/did.json

Nebulis commented 3 years ago

Thanks for the report, i've updated the documents (https://github.com/Open-Attestation/oa-verify/commit/f2c2022c9fe3f7bcdfae653937957ffc8e2e8692).

It's better to use open-attestation repository to get the most up-to-date documents