How I Bought Booze with a JSON Web Token

Angie Jones

Head of Developer Relations

@techgirl1908

Have you ever ordered alcohol

from a delivery app?

@techgirl1908

Physical Transaction

Online Transaction

=

=

+

>

>

>

@techgirl1908

Online Transaction Unfulfilled

=

+

>

>

>

>

@techgirl1908

Mobile Drivers License

@techgirl1908

Physical Transaction

Online Transaction

=

>

=

>

+

@techgirl1908

JSON Web Token

eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c

{
  "alg": "HS256",
  "typ": "JWT"
}
{
  "sub": "1234567890",
  "name": "John Doe",
  "iat": 1516239022
}
HMACSHA256(
  base64UrlEncode(header) + "." +
  base64UrlEncode(payload),
  
your-256-bit-secret

) secret base64 encoded

HEADER

PAYLOAD

SIGNATURE

@techgirl1908

JWT as Verifiable Credential

{
  "alg": "HS256",
  "typ": "JWT"
}
{
  "sub": "1234567890",
  "name": "John Doe",
  "iat": 1516239022
}
HMACSHA256(
  base64UrlEncode(header) + "." +
  base64UrlEncode(payload),
  
your-256-bit-secret

) secret base64 encoded

HEADER

PAYLOAD

SIGNATURE

{
  "alg": "EdDSA",
  "typ": "JWT",
  "kid": "did:dht:4mcuhc5merqam9hqq33cmk4k5kzajeq9shxkjydue61nc4em6i4o#0"
}
{
  "vc": {
    "@context": [
      "https://www.w3.org/2018/credentials/v1"
    ],
    "type": [
      "VerifiableCredential",
      "AgeOver21Credential"
    ],
    "id": "urn:uuid:0938d48d-ff0c-42b9-a9c4-6355b481095b",
    "issuer": "did:dht:4mcuhc5merqam9hqq33cmk4k5kzajeq9shxkjydue61nc4em6i4o",
    "issuanceDate": "2024-02-23T05:35:23Z",
    "credentialSubject": {
      "id": "did:dht:urtux8mi7nhtrgiyry5qbwb39ey4mpqidgnq3czkmp4zaoxcm5ty",
      "over21": true
    }
  },
  "iss": "did:dht:4mcuhc5merqam9hqq33cmk4k5kzajeq9shxkjydue61nc4em6i4o",
  "sub": "did:dht:urtux8mi7nhtrgiyry5qbwb39ey4mpqidgnq3czkmp4zaoxcm5ty"
}
HMACSHA256(
  base64UrlEncode(header) + "." +
  base64UrlEncode(payload),
  
your-256-bit-secret

) secret base64 encoded

HEADER

PAYLOAD

SIGNATURE

@techgirl1908

Verifiable Credential

{
  "vc": {
    "@context": [
      "https://www.w3.org/2018/credentials/v1"
    ],
    "type": [
      "VerifiableCredential",
      "AgeOver21Credential"
    ],
    "id": "urn:uuid:0938d48d-ff0c-42b9-a9c4-6355b481095b",
    "issuer": "did:dht:4mcuhc5merqam9hqq33cmk4k5kzajeq9shxkjydue61nc4em6i4o",
    "issuanceDate": "2024-02-23T05:35:23Z",
    "credentialSubject": {
      "id": "did:dht:urtux8mi7nhtrgiyry5qbwb39ey4mpqidgnq3czkmp4zaoxcm5ty",
      "over21": "true"
    }
  },
  "iss": "did:dht:4mcuhc5merqam9hqq33cmk4k5kzajeq9shxkjydue61nc4em6i4o",
  "sub": "did:dht:urtux8mi7nhtrgiyry5qbwb39ey4mpqidgnq3czkmp4zaoxcm5ty"
}

Verifiable Credentials Actors

Issuer

Holder

Verifier

issues credentials

acquires, stores, and presents

requests, verifies

@techgirl1908

Verifiable Credentials Actors

Issuer

Holder

Verifier

issues credentials

acquires, stores, and presents

requests, verifies

Which actor does the Customer play?

HOLDER

@techgirl1908

Verifiable Credentials Actors

Issuer

Holder

Verifier

issues credentials

acquires, stores, and presents

requests, verifies

Which does the Delivery App play?

VERIFIER

@techgirl1908

Verifiable Credentials Actors

Issuer

Holder

Verifier

issues credentials

acquires, stores, and presents

requests, verifies

Which does the License App play?

ISSUER

@techgirl1908

Verifiable Credentials Actors

Issuer

Holder

Verifier

issues credentials

acquires, stores, and presents

requests, verifies

Which does the Vendor play?

VERIFIER

@techgirl1908

const vc = await VerifiableCredential.create({
    type: 'AgeOver21Credential',
    issuer: issuerDid.uri,
    subject: holderDid.uri,
    data: {
        'over21': 'true'
    }
});

const vc_jwt = await vc.sign({ did: issuerDid });

Issuing the Credential

@techgirl1908

const pd = {
    "id": "PD-ALCOHOL-AGE-VERIFICATION",
    "name": "Alcohol Age Verification",
    "purpose": "Verification of legal age to purchase alcohol",
    "input_descriptors": [{
        "id": "AGE-OVER-21",
        "constraints": {
            "fields": [{
                "path": ["$.credentialSubject.over21"],
                "filter": {
                    "type": "string",
                    "const": "true"
                }
            }]
        }
    }]
};

Request VC

// Selects matching credentials
const selectedCredentials = 
      PresentationExchange.selectCredentials({
        vcJwts: credentials,
        presentationDefinition: pd
});

// Presents selected credentials
const presentationResult = 
      PresentationExchange.createPresentationFromCredentials({
        vcJwts: selectedCredentials,
        presentationDefinition: pd
});

Present JWT to Verifier

@techgirl1908

try{
    await VerifiableCredential.verify({ vcJwt: vc });
  
    PresentationExchange.satisfiesPresentationDefinition({
    	vcJwts: selectedCredentials,
    	presentationDefinition: presentationDefinition
  	});
}catch(e){
    console.error(e);
}

Verify VC

@techgirl1908

Education Credential

photo credit: verifiablecredentials.dev

Employment Credential 

@techgirl1908

photo credit: verifiablecredentials.dev

@techgirl1908

💼 proof of employment history

 

🎓 degree in a field related to Engineering, Computer Science, or Security

 

OR

 

🥷🏼 Certified Ethical Hacker certification issued by a specific trusted organization

Employment Application

Travel Credential

@techgirl1908

Medical Credential

@techgirl1908

photo credit: verifiablecredentials.dev

Financial Credential

@techgirl1908

Security

How do I keep my credentials safe?

@techgirl1908

Challenges

What is the biggest challenge you see with adoption?

@techgirl1908

@techgirl1908

developer.tbd.website

@techgirl1908

Cheers to VCs!

How I Bought Booze with a JSON Web Token

By Angie Jones

How I Bought Booze with a JSON Web Token

A practical demonstration of creating and sharing verifiable credentials in the form of JWTs. Learn how these credentials not only enhance efficiency but also uphold privacy in online transactions.

  • 34