Skip to content
This repository has been archived by the owner on Dec 12, 2024. It is now read-only.

a GUI for issuing VCs and DIDs #89

Merged
merged 4 commits into from
Sep 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions build/Dockerfile-gui
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM python:3.10-slim-buster
COPY ./gui/requirements.txt /app/requirements.txt
WORKDIR /app
RUN pip install -r requirements.txt
COPY ./gui /app
EXPOSE 8501
ENTRYPOINT ["streamlit","run"]
CMD ["streamlit.py"]
8 changes: 8 additions & 0 deletions build/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ services:
volumes:
- ../doc/swagger.yaml:/app/swagger.yaml
command: ["serve", "/app/swagger.yaml", "--no-open", "--port", "8080"]
gui:
build:
context: ../
dockerfile: build/Dockerfile-gui
ports:
- "8081:8501"
depends_on:
- web
jaeger:
image: jaegertracing/all-in-one:latest
ports:
Expand Down
8 changes: 8 additions & 0 deletions gui/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Simple GUI for DID and VC

Streamlit (https://streamlit.io/) is a popular data exploration and sharing app to for quick web prototyping.
This allows you to play around with the ssi-service from a web GUI to explore the concepts.

It is also easy to modify and add pages/features to demonstate the applications of SSI.

When run via `docker-compose up` it will be available at localhost:8081 (main web service is on port 8080)
1 change: 1 addition & 0 deletions gui/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
streamlit
113 changes: 113 additions & 0 deletions gui/streamlit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
from pickletools import read_bytes1
import streamlit as st
import requests
import json

st.title('DID and Verifiable Credentials')


#
# Show health and readitness in the sidebar
#

health = requests.get('http://web:3000/health').json()
readiness = requests.get('http://web:3000/readiness').json()
ready = readiness['status']['status']

with st.sidebar:

with st.expander("Service detail"):
st.write(health)
st.write(readiness)

if health['status'] == "OK" and ready == "ready":
st.success("service: " + health['status'])
else:
st.error("service: " + str(health.json()['status']))
st.write(readiness)


for state in readiness['serviceStatuses']:
if readiness['serviceStatuses'][state]['status'] == "ready":
st.success(state + ": " + readiness['serviceStatuses'][state]['status'])
else:
st.error(readiness['serviceStatuses'][state]['status'])



if 'did' not in st.session_state:
st.subheader("Create a DID:")

if st.radio("Make or load a DID", ["Create new DID", "Use existing DID"]) == "Create new DID":
if st.button("Create new DID"):
did = requests.put('http://web:3000/v1/dids/key', data=json.dumps({"keyType":"Ed25519"})).json()
st.session_state.did = did
st.experimental_rerun()
else:
st.stop()

else:
key = st.text_input("", "did:example:1234")
if st.button("Lookup DID"):
did = requests.get('http://web:3000/v1/dids/key/' + key).json()
st.session_state.did = did
st.experimental_rerun()
else:
st.stop()

did = st.session_state.did


st.text("DID chosen: " + did['did']['id'])

with st.expander("(optional) Show DID detail"):
st.write(did)





st.subheader("Choose a schema to issue a Verifiable Credential against:")

@st.cache
def load_schemas():
schemas = requests.get('https://schema.org/version/latest/schemaorg-current-https.jsonld').json()

listing = []
for schema in schemas["@graph"]:
listing.append(schema["@id"])

return listing

schemas = load_schemas()
default_schema = "schema:PostalAddress"
schema = st.selectbox(options=schemas, label='Select a schema', index=schemas.index(default_schema))





st.subheader("Issue a Verifiable Credential:")

expiry = st.date_input("Expiry date:", value=None, min_value=None, max_value=None, key=None, help=None)
# convert to ISO 8601
expiry = expiry.isoformat()


data = {
"addressLocality": "Paris, France",
"postalCode": "75002",
"streetAddress": "38 avenue de l'\''Opera"
}
data = st.text_area("Data for credential (depends on schema):", value=json.dumps(data), height=None, max_chars=None, key=None, help=None)

if st.button("Issue Verifiable Credential"):
payload = {
"Issuer": did['did']['id'],
"Subject": did['did']['id'],
"Schema": "https://schema.org/" + schema.split(":")[1],
"Data": json.loads(data),
"Expiry": str(expiry) + "T00:00:00+00:00"
}
vc = requests.put('http://web:3000/v1/credentials', data=json.dumps(payload)).json()
st.write(vc)