new way for to get a new did

This commit is contained in:
Cayo Puigdefabregas 2023-11-14 09:48:36 +01:00
parent add3747321
commit 6cf289f5b1
3 changed files with 13 additions and 5 deletions

View file

@ -20,7 +20,6 @@ from django.shortcuts import get_object_or_404, redirect
from django.urls import reverse_lazy
from django.http import HttpResponse
from django.contrib import messages
from utils.apiregiter import iota
from utils import credtools
from idhub_auth.models import User
from idhub.mixins import AdminView
@ -511,7 +510,7 @@ class DidRegisterView(Credentials, CreateView):
def form_valid(self, form):
form.instance.user = self.request.user
form.instance.did = iota.issue_did()
form.instance.set_did()
form.save()
messages.success(self.request, _('DID created successfully'))
return super().form_valid(form)

View file

@ -2,6 +2,7 @@ import json
import requests
from django.db import models
from django.utils.translation import gettext_lazy as _
from idhub_ssikit import generate_did_controller_key
from idhub_auth.models import User
@ -14,7 +15,6 @@ from idhub_auth.models import User
class DID(models.Model):
created_at = models.DateTimeField(auto_now=True)
did = models.CharField(max_length=250, unique=True)
label = models.CharField(max_length=50)
# In JWK format. Must be stored as-is and passed whole to library functions.
# Example key material:
@ -33,6 +33,16 @@ class DID(models.Model):
return True
return False
@property
def did(self):
return self.get_key().get("d")
def set_did(self):
self.key_material = idhub_ssikit.generate_did_controller_key()
def get_key(self):
return json.loads(self.key_material)
class Schemas(models.Model):
file_schema = models.CharField(max_length=250)

View file

@ -12,7 +12,6 @@ from django.shortcuts import get_object_or_404, redirect
from django.urls import reverse_lazy
from django.http import HttpResponse
from django.contrib import messages
from utils.apiregiter import iota
from idhub.user.forms import ProfileForm, RequestCredentialForm, CredentialPresentationForm
from idhub.mixins import UserView
from idhub.models import DID, VerificableCredential
@ -183,7 +182,7 @@ class DidRegisterView(MyWallet, CreateView):
def form_valid(self, form):
form.instance.user = self.request.user
form.instance.did = iota.issue_did()
form.instance.set_did()
form.save()
messages.success(self.request, _('DID created successfully'))
return super().form_valid(form)