digitalcredentials / sandbox

DCC developer playground
https://digitalcredentials.github.io/sandbox/
MIT License
5 stars 5 forks source link

Encode credentials into qr codes with cborld #16

Closed kezike closed 3 years ago

kezike commented 3 years ago

Encoding credentials into QR Codes with CBOR-LD via Digital Bazaar's vpqr library

Here is a sample credential:

{
  "@context": [
    "https://www.w3.org/2018/credentials/v1",
    "https://w3id.org/security/suites/ed25519-2020/v1",
    "https://w3id.org/dcc/v1"
  ],
  "id": "https://digitalcredentials.github.io/samples/certificate/1fe91f0f-4c64-48c8-bfc8-7132f75776fe/",
  "type": [
    "VerifiableCredential",
    "LearningCredential"
  ],
  "issuer": {
    "type": "Issuer",
    "id": "did:web:digitalcredentials.github.io",
    "name": "Sample Issuer",
    "url": "https://digitalcredentials.github.io/samples/"
  },
  "issuanceDate": "2021-01-19T18:22:34.772810+00:00",
  "credentialSubject": {
    "type": "Person",
    "id": "did:example:456",
    "name": "Percy",
    "hasCredential": {
      "type": [
        "EducationalOccupationalCredential",
        "ProgramCompletionCredential"
      ],
      "name": "DCC Program Completion Credential",
      "description": "Awarded on completion of the digital credential program",
      "awardedOnCompletionOf": {
        "type": "EducationalOccupationalProgram",
        "identifier": "program-v1:Sample",
        "name": "Digital Credential Program",
        "description": "Educational program teaching how work with digital credentials",
        "numberOfCredits": {
          "value": "1"
        },
        "startDate": "",
        "endDate": ""
      }
    }
  }
}

and its associated QR Code qr-code

kezike commented 3 years ago

@dmitrizagidulin In this PR, I am using vpqr to encode the VC directly. Should I be placing the VC into a VP envelope before using this library or is it able to encode VCs as expected. I assume the library accepts and treats both formats the same way, but I just want to be sure.

dmitrizagidulin commented 3 years ago

Should I be placing the VC into a VP envelope before using this library or is it able to encode VCs as expected. I assume the library accepts and treats both formats the same way, but I just want to be sure.

You definitely want to place the VC into a VP envelope. In general, un-wrapped VCs should only exist inside the wallet / VC storage; they shouldn't really be encountered in the wild.

kezike commented 3 years ago

Should I be placing the VC into a VP envelope before using this library or is it able to encode VCs as expected. I assume the library accepts and treats both formats the same way, but I just want to be sure.

You definitely want to place the VC into a VP envelope. In general, un-wrapped VCs should only exist inside the wallet / VC storage; they shouldn't really be encountered in the wild.

Makes sense! I have updated the PR to package a VC into an unsigned VP before encoding it into a QR Code URL. I have also implemented the ProvePresentationRequest method to interface with the /prove/presentations endpoint of the sign-and-verify API, but this will only become relevant after we host a sign-and-verify instance.