add idhub_ssikit in utils

This commit is contained in:
Cayo Puigdefabregas 2023-11-14 18:12:34 +01:00
parent 28796e9df3
commit 2df87faf80
7 changed files with 10 additions and 8 deletions

View File

@ -1,4 +1,4 @@
# Generated by Django 4.2.5 on 2023-11-14 16:48
# Generated by Django 4.2.5 on 2023-11-14 17:08
from django.conf import settings
from django.db import migrations, models
@ -289,6 +289,7 @@ class Migration(migrations.Migration):
),
('created_at', models.DateTimeField(auto_now=True)),
('label', models.CharField(max_length=50)),
('did', models.CharField(max_length=250)),
('key_material', models.CharField(max_length=250)),
(
'user',

View File

@ -3,7 +3,10 @@ import requests
import datetime
from django.db import models
from django.utils.translation import gettext_lazy as _
from idhub_ssikit import generate_did_controller_key
from utils.idhub_ssikit import (
generate_did_controller_key,
keydid_from_controller_key,
)
from idhub_auth.models import User
@ -398,6 +401,7 @@ class Event(models.Model):
class DID(models.Model):
created_at = models.DateTimeField(auto_now=True)
label = models.CharField(max_length=50)
did = models.CharField(max_length=250)
# In JWK format. Must be stored as-is and passed whole to library functions.
# Example key material:
# '{"kty":"OKP","crv":"Ed25519","x":"oB2cPGFx5FX4dtS1Rtep8ac6B__61HAP_RtSzJdPxqs","d":"OJw80T1CtcqV0hUcZdcI-vYNBN1dlubrLaJa0_se_gU"}'
@ -415,12 +419,9 @@ 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()
self.key_material = generate_did_controller_key()
self.did = keydid_from_controller_key(self.key_material)
def get_key(self):
return json.loads(self.key_material)

View File

@ -1,4 +1,4 @@
# Generated by Django 4.2.5 on 2023-11-14 16:48
# Generated by Django 4.2.5 on 2023-11-14 17:08
from django.db import migrations, models