merged walletkit/ssikit api bindings

This commit is contained in:
Daniel Armengod 2023-10-10 08:55:53 +02:00
commit 4226683c84
13 changed files with 297 additions and 13 deletions

View file

@ -1,3 +1,5 @@
from django.contrib import admin
# Register your models here.
from .models import AppUser
admin.site.register(AppUser)

View file

@ -0,0 +1,56 @@
# Generated by Django 4.2.5 on 2023-10-03 15:28
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.CreateModel(
name='DID',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('did_string', models.CharField(max_length=250)),
],
options={
'abstract': False,
},
),
migrations.CreateModel(
name='Event',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('timestamp', models.DateTimeField()),
],
),
migrations.CreateModel(
name='VerifiableCredential',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('id_string', models.CharField(max_length=250)),
('data', models.TextField()),
('verified', models.BooleanField()),
('created_on', models.DateTimeField()),
('did_issuer', models.CharField(max_length=250)),
('did_subject', models.CharField(max_length=250)),
],
options={
'abstract': False,
},
),
migrations.CreateModel(
name='AppUser',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('django_user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
]

View file

@ -2,27 +2,41 @@ from django.db import models
from django.contrib.auth.models import User as DjangoUser
class User(DjangoUser):
class AppUser(models.Model):
# Ya incluye "first_name", "last_name", "email", y "date_joined" heredando de la clase User de django.
# Falta ver que más información hay que añadir a nuestros usuarios, como los roles etc.
django_user = models.OneToOneField(DjangoUser, on_delete=models.CASCADE)
# Extra data, segun entidad/organizacion
pass
class Event(models.Model):
# Para los "audit logs" que se requieren en las pantallas.
timestamp = models.DateTimeField()
kind = "PLACEHOLDER"
# Los eventos no tienen relación con otros objetos a nivel de BBDD.
event_data = models.CharField(max_length=250)
class DID(models.Model):
did_string = models.CharField(max_length=250)
# kind = "KEY|JWK|WEB|EBSI|CHEQD|IOTA"
label = models.CharField(max_length=50)
owner = models.ForeignKey(AppUser, on_delete=models.CASCADE)
# kind = "KEY|WEB"
class VerifiableCredential(models.Model):
id_string = models.CharField(max_length=250)
data = models.TextField()
verified = models.BooleanField()
created_on = models.DateTimeField()
did_issuer = models.ForeignKey(DID, on_delete=models.PROTECT)
did_subject = models.ForeignKey(DID, on_delete=models.PROTECT)
did_issuer = models.CharField(max_length=250)
did_subject = models.CharField(max_length=250)
owner = models.ForeignKey(AppUser, on_delete=models.CASCADE)
data = models.TextField()
class VCTemplate(models.Model):
wkit_template_id = models.CharField(max_length=250)
data = models.TextField()

View file

@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<form action="{% url 'user' %}" method="post">
{% csrf_token %}
{{ form }}
<input type="submit" value="Submit">
</form>
</body>
</html>

View file

@ -0,0 +1,7 @@
<!-- templates/registration/login.html -->
<h2>Log In</h2>
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<button type="submit">Log In</button>
</form>

View file

@ -21,7 +21,6 @@ from .views import LoginView
from .admin import views as views_admin
from .user import views as views_user
app_name = 'idhub'
urlpatterns = [

View file

@ -1,4 +1,3 @@
from django.urls import reverse_lazy
from django.utils.translation import gettext_lazy as _
from django.contrib.auth import views as auth_views

View file

@ -37,9 +37,9 @@ INSTALLED_APPS = [
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'idhub'
'django_extensions',
'bootstrap4',
'idhub'
]
MIDDLEWARE = [

View file

@ -0,0 +1,123 @@
"""
Django settings for trustchain_idhub project.
Generated by 'django-admin startproject' using Django 4.2.5.
For more information on this file, see
https://docs.djangoproject.com/en/4.2/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.2/ref/settings/
"""
from pathlib import Path
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-os^a#c(i*z8*=o4#b%xsno97_!pqsv*or_5&lcga7&+u53(p92'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'trustchain_idhub.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'trustchain_idhub.wsgi.application'
# Database
# https://docs.djangoproject.com/en/4.2/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
# Password validation
# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/4.2/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.2/howto/static-files/
STATIC_URL = 'static/'
# Default primary key field type
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

View file

@ -18,6 +18,9 @@ Including another URLconf
# from django.contrib import admin
from django.urls import path, include
from django.contrib.auth import views as auth_views
urlpatterns = [
# path('django-admin/', admin.site.urls),
path('', include('idhub.urls')),

View file

@ -0,0 +1,15 @@
{
"issuerApiUrl": "http://localhost:8080/issuer-api/default",
"issuerClientName": "PANGEA Issuer Portal",
"issuerDid": null,
"issuerUiUrl": "http://localhost:5000",
"wallets": {
"walt.id": {
"description": "walt.id web wallet",
"id": "walt.id",
"presentPath": "api/siop/initiatePresentation",
"receivePath": "api/siop/initiateIssuance",
"url": "http://localhost:3000"
}
}
}

View file

@ -0,0 +1,52 @@
from pathlib import Path
import requests
import json
WALLETKITD = 'http://localhost:8080/'
ISSUER = f'{WALLETKITD}issuer-api/default/'
VERIFIER = f'{WALLETKITD}verifier-api/default/'
default_ctype_header = {
'Content-Type': 'application/json', # specify the type of data you're sending
'Accept': 'application/json', # specify the type of data you can accept
}
def include_str(path):
with open(path, "r") as f:
return f.read().strip()
# Create DID for tenant
# Valid methods: 'key'|'web'
def user_create_did(did_method):
url = f'{ISSUER}config/did/create'
data = {
'method': did_method
}
response = requests.post(url, json=data, headers=default_ctype_header)
response.raise_for_status()
return response.text
def admin_create_template(template_name, template_body):
url = f'{ISSUER}config/templates/{template_name}'
body = template_body
response = requests.post(url, data=body, headers=default_ctype_header)
response.raise_for_status()
return
def user_issue_vc(vc_name, vc_params):
url = f'{ISSUER}credentials/issuance/request'
# ...
# TODO examine cross-device issuance workflow
pass
TENANT_CFG_TMEPLATE = include_str("./TENANT_CFG_TEMPLATE")

View file

@ -1,11 +1,11 @@
/user/event-log [GET] -> vista d'esdeveniments
sense enllaços rapids a les accions
/user [GET, POST] -> vista de dades personals
/user/dashboard [GET, POST] -> vista de dades personals
/user/roles [GET] -> vista de rols (????)
/user/gdpr [GET] -> info de la gdpr
/user/wallet/dids [GET, PUT]
/user/wallet/dids/<id:integer> [DELETE]
/user/wallet/dids [GET, POST]
/user/wallet/dids/<id:integer> [GET, DELETE]
/user/credentials [GET]
/user/credentials/<id:integer> [GET, DELETE]
/user/credentials/request [GET, POST]