Skip to content

Commit

Permalink
Merge pull request #5 from decentralgabe/feat/other-media-types
Browse files Browse the repository at this point in the history
Update rendering to support other media types
  • Loading branch information
OR13 authored Feb 17, 2024
2 parents 3d4765e + 5117c0f commit 3a417ac
Show file tree
Hide file tree
Showing 19 changed files with 10,555 additions and 3,690 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/static.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Simple workflow for deploying static content to GitHub Pages
name: Deploy static content to Pages

on:
# Runs on pushes targeting the default branch
push:
branches: ["main"]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write

# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
group: "pages"
cancel-in-progress: false

jobs:
# Single deploy job since we're just deploying
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Pages
uses: actions/configure-pages@v4
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
# Upload entire repository
path: '.'
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@

.idea
.DS_Store
node_modules
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Verifiable Credential Service Worker Plugin for ReSpec

- [demo](https://transmute-industries.github.io/respec-vc-jwt/)
- [demo](https://decentralgabe.github.io/respec-vc-jose-cose/)

But with support for v2, and no JSON-LD processing.

Expand All @@ -16,17 +16,16 @@ then configure respect to use the worker to post process like so:
<title>Respec Service Worker Plugin Test</title>
<meta http-equiv='Content-Type' content='text/html;charset=utf-8' />
<script src='https://www.w3.org/Tools/respec/respec-w3c' class='remove'></script>
<script src='./respec-plugins/vc-jose-cose.js'></script>
<link rel="stylesheet" href="./respec-plugins/vc-jose-cose.css">
<script src="https://cdn.jsdelivr.net/gh/decentralgabe/respec-vc-jose-cose/dist/main.js"></script>
<script type="text/javascript" class="remove">
var respecConfig = {
// ...
postProcess: [postProcessWithWorker]
postProcess: [window.respecVcJoseCose.processVcJoseCose]
};
</script>
</head>
```

### Credits

Based on the original plugin here https://github.com/digitalbazaar/respec-vc
Based on https://github.com/transmute-industries/respec-vc-jwt, which was based on the original plugin here https://github.com/digitalbazaar/respec-vc
5 changes: 3 additions & 2 deletions src/sd-jwt/index.js → attic/sd-jwt/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ export const generateHolderDisclosure = (example) => {
return edited3
}

export const getExampleMetadata = async ({ alg, json }) => {
export const getExampleMetadata = async ({ alg, json }) => {
console.log('getExampleMetadata', { alg, json })
let iss = undefined

if(json.issuer){
Expand All @@ -51,7 +52,7 @@ export const getExampleMetadata = async ({ alg, json }) => {
if (json.holder){
iss = typeof json.holder === 'string' ? json.holder: json.holder.id
}

const iat = moment().unix();
const exp = moment().add(1, 'years').unix();
const nonce = salter()
Expand Down
9,522 changes: 9,522 additions & 0 deletions dist/main.js

Large diffs are not rendered by default.

73 changes: 23 additions & 50 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,21 @@
<title>Respec Service Worker Plugin Test</title>
<meta http-equiv='Content-Type' content='text/html;charset=utf-8' />
<script src='https://www.w3.org/Tools/respec/respec-w3c' class='remove'></script>
<script src='./respec-plugins/vc-jose-cose.js'></script>
<link rel="stylesheet" href="./respec-plugins/vc-jose-cose.css">
<script src='./dist/main.js'></script>
<script type="text/javascript" class="remove">
var respecConfig = {
group: "vc",
specStatus: "unofficial",
subtitle: "Test of ReSpec VC",
edDraftURI: "https://transmute-industries.github.io/respec-vc-jwt/",
latestVersion: "https://transmute-industries.github.io/respec-vc-jwt/",
edDraftURI: "https://decentralgabe.github.io/respec-vc-jose-cose/",
latestVersion: "https://decentralgabe.github.io/respec-vc-jose-cose/",
doJsonLd: false,
github: "https://github.com/transmute-industries/respec-vc-jwt",
github: "https://github.com/transmute-industries/respec-vc-jose-cose",
includePermalinks: false,
editors: [
{
name: "Orie Steele", url: "https://www.linkedin.com/in/or13b/",
company: "Transmute", companyURL: "http://transmute.industries/"
name: "Gabe Cohen", url: "https://www.linkedin.com/in/cohengabe/",
company: "Transmute", companyURL: "http://decentralgabe.xyz/"
}
],
authors:
Expand All @@ -32,7 +31,7 @@
],
maxTocLevel: 2,
inlineCSS: true,
postProcess: [postProcessWithWorker]
postProcess: [window.respecVcJoseCose.processVcJoseCose]
};
</script>
</head>
Expand Down Expand Up @@ -63,14 +62,6 @@ <h2>Credential</h2>
"id": "did:example:c276e12ec21ebfeb1f712ebc6f1",
"name": "Example University"
}
},
"proof": {
"type": "DataIntegrityProof",
"cryptosuite": "eddsa-2022",
"created": "2023-06-18T21:19:10Z",
"proofPurpose": "assertionMethod",
"verificationMethod": "https://university.example/issuers/565049#key-123",
"proofValue": "zQeVbY4oey5q2M3XKaxup3tmzN4DRFTLVqpLMweBrSxMY2xHX5XTYV8nQApmEcqaqA3Q1gVHMrXFkXJeV6doDwLWx"
}
}
</pre>
Expand All @@ -86,44 +77,26 @@ <h2>Presentation</h2>
"https://www.w3.org/ns/credentials/examples/v2"
],
"type": "VerifiablePresentation",
"verifiableCredential": [{
"@context": [
"https://www.w3.org/ns/credentials/v2",
"https://www.w3.org/ns/credentials/examples/v2"
],
"id": "http://university.example/credentials/1872",
"type": ["VerifiableCredential", "ExampleAlumniCredential"],
"issuer": "https://university.example/issuers/565049",
"validFrom": "2010-01-01T19:23:24Z",
"credentialSubject": {
"id": "did:example:ebfeb1f712ebc6f1c276e12ec21",
"alumniOf": {
"id": "did:example:c276e12ec21ebfeb1f712ebc6f1",
"name": "Example University"
}
"verifiableCredential": [
{
"@context": "https://www.w3.org/ns/credentials/v2",
"id": "data:application/vc+ld+json+cose;base64url,QzVjV...RMjU",
"type": "EnvelopedVerifiableCredential"
},
"proof": {
"type": "DataIntegrityProof",
"cryptosuite": "eddsa-2022",
"created": "2023-06-18T21:19:10Z",
"proofPurpose": "assertionMethod",
"verificationMethod": "https://university.example/issuers/565049#key-1",
"proofValue": "zQeVbY4oey5q2M3XKaxup3tmzN4DRFTLVqpLMweBrSxMY2xHX5XTYV8nQApmEcqaqA3Q1gVHMrXFkXJeV6doDwLWx"
{
"@context": "https://www.w3.org/ns/credentials/v2",
"id": "data:application/vc+ld+json+jwt;eyVjV...RMjU",
"type": "EnvelopedVerifiableCredential"
},
{
"@context": "https://www.w3.org/ns/credentials/v2",
"id": "data:application/vc+ld+json+sd-jwt;eyVjV...RMjU",
"type": "EnvelopedVerifiableCredential"
}
}],
"proof": {
"type": "DataIntegrityProof",
"cryptosuite": "eddsa-2022",
"created": "2018-09-14T21:19:10Z",
"proofPurpose": "authentication",
"verificationMethod": "did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1",
"challenge": "1f44d55f-f161-4938-a659-f8026467f126",
"domain": "4jt78h47fh47",
"proofValue": "zqpLMweBrSxMY2xHX5XTYV8nQAJeV6doDwLWxQeVbY4oey5q2pmEcqaqA3Q1gVHMrXFkXM3XKaxup3tmzN4DRFTLV"
}
]
}
</pre>
</section>
</body>

</html>
</html>
131 changes: 129 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,130 @@
import { eventHandler } from "./src/eventHandler";

self.addEventListener("message", eventHandler);
import {getHtml} from './src/getHtml';

import { getPrivateKey } from './src/exampleKey';
import { getCoseExample } from './src/exampleCose';
import { getJwtExample } from './src/exampleJwt';
import { getSdJwtExample } from './src/exampleSdJwt';



async function processVcJoseCose() {
// add styling for examples
addVcJoseStyles();
const examples = Array.from(document.querySelectorAll(".vc-jose-cose")).filter((e) => !!e.innerText)
for (const index in examples) {
const example = examples[index]
const json = JSON.parse(example.innerText.replace(/\/\/ .*$/gm, ''))
const processedData = await processExample(index, json);
example.outerHTML = processedData.html
}
}

function addVcJoseStyles() {
const styles = document.createElement('style');

styles.innerHTML += `
.vc-jose-cose-tabbed {
overflow-x: hidden;
margin: 0 0;
}
.vc-jose-cose-tabbed h1 {
font-size: 1em;
}
.vc-jose-cose-tabbed [type="radio"] {
display: none;
}
.vc-jose-cose-tabs {
display: flex;
align-items: stretch;
list-style: none;
padding: 0;
border-bottom: 1px solid #ccc;
}
li.vc-jose-cose-tab {
margin: unset;
margin-left: 8px;
}
.vc-jose-cose-tab>label {
display: block;
margin-bottom: -1px;
padding: .4em .5em;
border: 1px solid #ccc;
border-top-right-radius: .4em;
border-top-left-radius: .4em;
background: #eee;
color: #666;
cursor: pointer;
transition: all 0.3s;
}
.vc-jose-cose-tab:hover label {
border-left-color: #333;
border-top-color: #333;
border-right-color: #333;
color: #333;
}
.vc-jose-cose-tab-content {
display: none;
}
.vc-jose-cose-tabbed [type="radio"]:nth-of-type(1):checked~.vc-jose-cose-tabs .vc-jose-cose-tab:nth-of-type(1) label,
.vc-jose-cose-tabbed [type="radio"]:nth-of-type(2):checked~.vc-jose-cose-tabs .vc-jose-cose-tab:nth-of-type(2) label,
.vc-jose-cose-tabbed [type="radio"]:nth-of-type(3):checked~.vc-jose-cose-tabs .vc-jose-cose-tab:nth-of-type(3) label {
border-bottom-color: #fff;
background: #fff;
color: #222;
}
.vc-jose-cose-tabbed [type="radio"]:nth-of-type(1):checked~.vc-jose-cose-tab-content:nth-of-type(1),
.vc-jose-cose-tabbed [type="radio"]:nth-of-type(2):checked~.vc-jose-cose-tab-content:nth-of-type(2),
.vc-jose-cose-tabbed [type="radio"]:nth-of-type(3):checked~.vc-jose-cose-tab-content:nth-of-type(3) {
display: block;
}
.sd-jwt-header, .jwt-header {
color: red
}
.sd-jwt-payload, .jwt-payload {
color: green
}
.sd-jwt-signature, .jwt-signature {
color: blue
}
.sd-jwt-disclosure {
color: purple
}
.sd-jwt-compact, .jwt-compact {
background-color: rgba(0,0,0,.03);
}
.cose-text, .jose-text {
font-family: monospace;
}
`;

document.head.appendChild(styles);
}

export async function processExample(index, json) {
const privateKey = await getPrivateKey();
const coseExample = await getCoseExample(privateKey, json);
const jwtExample = await getJwtExample(privateKey, json);
const sdJwtExample = await getSdJwtExample(privateKey, json);
const html = getHtml({index, coseExample, jwtExample, sdJwtExample});
return {html};
}

window.respecVcJoseCose = {
processVcJoseCose
}
Loading

0 comments on commit 3a417ac

Please sign in to comment.