From 2df87faf80d2414e7753ea887788267002b200a4 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Tue, 14 Nov 2023 18:12:34 +0100 Subject: [PATCH] add idhub_ssikit in utils --- idhub/migrations/0001_initial.py | 3 ++- idhub/models.py | 13 +++++++------ .../templates/credentials}/member-credential.json | 0 idhub_auth/migrations/0001_initial.py | 2 +- {idhub_ssikit => utils/idhub_ssikit}/README.md | 0 .../idhub_ssikit}/TENANT_CFG_TEMPLATE | 0 {idhub_ssikit => utils/idhub_ssikit}/__init__.py | 0 7 files changed, 10 insertions(+), 8 deletions(-) rename {schemas => idhub/templates/credentials}/member-credential.json (100%) rename {idhub_ssikit => utils/idhub_ssikit}/README.md (100%) rename {idhub_ssikit => utils/idhub_ssikit}/TENANT_CFG_TEMPLATE (100%) rename {idhub_ssikit => utils/idhub_ssikit}/__init__.py (100%) diff --git a/idhub/migrations/0001_initial.py b/idhub/migrations/0001_initial.py index cdd6262..e95751c 100644 --- a/idhub/migrations/0001_initial.py +++ b/idhub/migrations/0001_initial.py @@ -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', diff --git a/idhub/models.py b/idhub/models.py index b74f9dc..68a0f8d 100644 --- a/idhub/models.py +++ b/idhub/models.py @@ -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) diff --git a/schemas/member-credential.json b/idhub/templates/credentials/member-credential.json similarity index 100% rename from schemas/member-credential.json rename to idhub/templates/credentials/member-credential.json diff --git a/idhub_auth/migrations/0001_initial.py b/idhub_auth/migrations/0001_initial.py index 3400ba6..c15aee0 100644 --- a/idhub_auth/migrations/0001_initial.py +++ b/idhub_auth/migrations/0001_initial.py @@ -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 diff --git a/idhub_ssikit/README.md b/utils/idhub_ssikit/README.md similarity index 100% rename from idhub_ssikit/README.md rename to utils/idhub_ssikit/README.md diff --git a/idhub_ssikit/TENANT_CFG_TEMPLATE b/utils/idhub_ssikit/TENANT_CFG_TEMPLATE similarity index 100% rename from idhub_ssikit/TENANT_CFG_TEMPLATE rename to utils/idhub_ssikit/TENANT_CFG_TEMPLATE diff --git a/idhub_ssikit/__init__.py b/utils/idhub_ssikit/__init__.py similarity index 100% rename from idhub_ssikit/__init__.py rename to utils/idhub_ssikit/__init__.py