gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnunet] branch master updated (cc70504a2 -> 4a2c758df)


From: gnunet
Subject: [gnunet] branch master updated (cc70504a2 -> 4a2c758df)
Date: Wed, 31 Aug 2022 17:59:54 +0200

This is an automated email from the git hooks/post-receive script.

martin-schanzenbach pushed a change to branch master
in repository gnunet.

    from cc70504a2 Merge branch 'dev/trizuz/siop'
     new 841bf3572 DID:Initial commit
     new f3fec1be8 - get did document test
     new d83d7be67 -forgot the .c...
     new 37569e7e9 - DID remove
     new 25481cc07 remove binary
     new 4597a6d7e - Not working did remove
     new 6a762139b - did working remove
     new 806c8c808 -DID refactor, uncrustify, not working didd create
     new 6f43bf90f - did not working create
     new c8752d7bc -did show did and refactor
     new fe2413f42 -add test for w3c-ed25519-2020
     new ec74cd273 -proper license header
     new a22f99e9a -test against mb b64
     new f1da382ae -did not working remove abstraction
     new 74803406f -did not working remove
     new d0edc1f7d -did working replace, generalized remove, refactor
     new ac07d007e -did expiration time fix
     new 2730aad87 -did not working key check
     new ba63a4a0a -did key check
     new 75eb920d6 -did mulitbase key and assert method for VCs
     new 8685ef460 DID:Initial commit
     new beb5129ec - get did document test
     new 460c7ffbd -forgot the .c...
     new a23adee0d - DID remove
     new bcaf1b1f0 remove binary
     new 57ee0611b Merge branch 'dev/trizuz/dids' of 
git+ssh://git.gnunet.org/gnunet into dev/trizuz/dids
     new fc1a0eead - Not working did remove
     new f1d0f54c0 - did working remove
     new 3395a5af8 -DID refactor, uncrustify, not working didd create
     new 2944a813c - did not working create
     new 237b03c46 -did show did and refactor
     new 5071679e4 -add test for w3c-ed25519-2020
     new 57a1e42ed -proper license header
     new 1c895918c -test against mb b64
     new 50ed616a7 Merge branch 'dev/trizuz/dids' of 
git+ssh://git.gnunet.org/gnunet into dev/trizuz/dids
     new 0255f33c9 -did not working remove abstraction
     new 8e685158f -did not working remove
     new 3586f9360 -did working replace, generalized remove, refactor
     new 5a272fc92 -did expiration time fix
     new 7779d8b9d -did not working key check
     new a382fd276 -did key check
     new 11a37cc31 -did mulitbase key and assert method for VCs
     new 32caf8fa4 -mergefix
     new 0d605eac2 -add comments
     new 821db736f fix bugs
     new 7064aca61 -code review
     new df8660ffe -move to reclaim
     new 87e8f46b7 - started DID refactor
     new a3af7211c - init did test
     new 9df46666f - not working test
     new fab645cae - trying to make did_helper a lib
     new 8d8e46d04 - working did lib and 1. test for did helper
     new 6649bed3a - more tests
     new 5ca196a44 - default did document test without multibase
     new 45d01b5d9 - finished DID helper with tests
     new ddd4bb9fc -header DID core
     new bc05f5201 - changed did_core header
     new 47e7cc4fd - missing lib bug
     new ec36e49c3 - DID resolve using DID lib
     new d3de2f84f - started with DID lib create func
     new b50b97b20 - non working DID lib create func
     new 2c8ab6b92 - refactored DID create
     new 00047451b - remove static variable from did_core
     new 9c008dbed - didlib; use expire value
     new 3b4032ef5 -m DID lib; added check for existing DID document
     new fe80bcfb8 - DID lib; renamed vars and moved a free
     new dcdb638c4 - DID lib; formatting
     new 41ed66d82 - DID lib; simplify closure
     new 6f72f1958 - added gitignores
     new 4a2c758df -fixup merge

The 70 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/reclaim/.gitignore        |   2 +
 src/reclaim/Makefile.am       |  44 +++-
 src/reclaim/did_core.c        | 267 +++++++++++++++++++++++
 src/reclaim/did_core.h        | 138 ++++++++++++
 src/reclaim/did_helper.c      | 203 ++++++++++++++++++
 src/reclaim/did_helper.h      |  74 +++++++
 src/reclaim/gnunet-did.c      | 482 +++++++++++-------------------------------
 src/reclaim/test_did_helper.c | 131 ++++++++++++
 8 files changed, 973 insertions(+), 368 deletions(-)
 create mode 100644 src/reclaim/did_core.c
 create mode 100644 src/reclaim/did_core.h
 create mode 100644 src/reclaim/did_helper.c
 create mode 100644 src/reclaim/did_helper.h
 create mode 100644 src/reclaim/test_did_helper.c

diff --git a/src/reclaim/.gitignore b/src/reclaim/.gitignore
index ac76b6b2f..e22aa5011 100644
--- a/src/reclaim/.gitignore
+++ b/src/reclaim/.gitignore
@@ -1,3 +1,5 @@
 gnunet-reclaim
 gnunet-service-reclaim
 gnunet-did
+test_did_helper
+test_reclaim_attribute
diff --git a/src/reclaim/Makefile.am b/src/reclaim/Makefile.am
index 2f3df3456..d29b5857a 100644
--- a/src/reclaim/Makefile.am
+++ b/src/reclaim/Makefile.am
@@ -38,7 +38,8 @@ pkgcfg_DATA = \
   reclaim.conf
 
 lib_LTLIBRARIES = \
-  libgnunetreclaim.la
+  libgnunetreclaim.la \
+  libgnunetdid.la
 plugin_LTLIBRARIES = \
   libgnunet_plugin_gnsrecord_reclaim.la \
   libgnunet_plugin_reclaim_attribute_basic.la \
@@ -142,6 +143,22 @@ libgnunetreclaim_la_LDFLAGS = \
   $(GN_LIB_LDFLAGS)   \
   -version-info 0:0:0
 
+libgnunetdid_la_SOURCES = \
+  did_helper.c \
+  did_helper.h \
+  did_core.h \
+  did_core.c
+libgnunetdid_la_LIBADD = \
+       $(top_builddir)/src/util/libgnunetutil.la \
+       $(top_builddir)/src/gns/libgnunetgns.la \
+       $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \
+       $(top_builddir)/src/identity/libgnunetidentity.la \
+       $(top_builddir)/src/namestore/libgnunetnamestore.la \
+       -ljansson \
+  $(GN_LIBINTL) $(XLIB)
+libgnunetdid_la_LDFLAGS = \
+  $(GN_LIB_LDFLAGS)   \
+  -version-info 0:0:0
 
 libgnunet_plugin_reclaim_attribute_basic_la_SOURCES = \
   plugin_reclaim_attribute_basic.c
@@ -194,22 +211,27 @@ test_reclaim_attribute_LDADD = \
   $(GN_LIBINTL)
 
 gnunet_did_SOURCES = \
-       gnunet-did.c \
-  did_misc.c \
-       did.h
+       gnunet-did.c
 gnunet_did_LDADD = \
        $(top_builddir)/src/util/libgnunetutil.la \
        $(top_builddir)/src/gns/libgnunetgns.la \
        $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \
        $(top_builddir)/src/identity/libgnunetidentity.la \
        $(top_builddir)/src/namestore/libgnunetnamestore.la \
+  libgnunetdid.la \
        -ljansson
 
 
-test_w3c_ed25519_2020_SOURCES = \
-  test_w3c_ed25519_2020.c
-test_w3c_ed25519_2020_LDADD = \
-  $(top_builddir)/src/util/libgnunetutil.la
+test_did_helper_SOURCES = \
+  test_did_helper.c
+test_did_helper_LDADD = \
+  $(top_builddir)/src/util/libgnunetutil.la \
+       $(top_builddir)/src/gns/libgnunetgns.la \
+       $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \
+       $(top_builddir)/src/identity/libgnunetidentity.la \
+       $(top_builddir)/src/namestore/libgnunetnamestore.la \
+  libgnunetdid.la \
+  -ljansson
 
 check_SCRIPTS = \
   test_reclaim_attribute.sh \
@@ -218,9 +240,11 @@ check_SCRIPTS = \
 
 check_PROGRAMS = \
   test_reclaim_attribute \
-  test_w3c_ed25519_2020
+  test_did_helper
 
 if ENABLE_TEST_RUN
  AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export 
PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH;unset XDG_DATA_HOME;unset 
XDG_CONFIG_HOME;
- TESTS = $(check_SCRIPTS)
+ TESTS = \
+  $(check_SCRIPTS) \
+  $(check_PROGRAMS)
 endif
diff --git a/src/reclaim/did_core.c b/src/reclaim/did_core.c
new file mode 100644
index 000000000..949ed6a69
--- /dev/null
+++ b/src/reclaim/did_core.c
@@ -0,0 +1,267 @@
+/*
+   This file is part of GNUnet
+   Copyright (C) 2010-2015 GNUnet e.V.
+
+   GNUnet is free software: you can redistribute it and/or modify it
+   under the terms of the GNU Affero General Public License as published
+   by the Free Software Foundation, either version 3 of the License,
+   or (at your option) any later version.
+
+   GNUnet is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Affero General Public License for more details.
+
+   You should have received a copy of the GNU Affero General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+   SPDX-License-Identifier: AGPL3.0-or-later
+ */
+
+/**
+ * @file reclaim/did_core.c
+ * @brief Core functionality for DID
+ * @author Tristan Schwieren
+ */
+
+// TODO: DID documents do not have an expiration date. Still we add one
+// TODO: Store DID document with empty label and own type (maybe DID-Document 
or JSON??)
+
+#include "did_core.h"
+
+struct DID_resolve_return
+{
+  DID_resolve_callback *cb;
+  void *cls;
+};
+
+struct DID_action_return
+{
+  DID_action_callback *cb;
+  void *cls;
+};
+
+// ------------------------------------------------ //
+// -------------------- Resolve ------------------- //
+// ------------------------------------------------ //
+
+/**
+ * @brief GNS lookup callback. Calls the given callback function
+ * and gives it the DID Document.
+ * Fails if there is more than one DID record.
+ *
+ * @param cls closure
+ * @param rd_count number of records in rd
+ * @param rd the records in the reply
+ */
+static void
+DID_resolve_gns_lookup_cb (
+  void *cls,
+  uint32_t rd_count,
+  const struct GNUNET_GNSRECORD_Data *rd)
+{
+  char *did_document;
+  DID_resolve_callback *cb = ((struct DID_resolve_return *) cls)->cb;
+  void *cls_did_resolve_cb = ((struct DID_resolve_return *) cls)->cls;
+  free (cls);
+
+  if (rd_count != 1)
+    cb (GNUNET_NO, "An ego should only have one DID Document",
+        cls_did_resolve_cb);
+
+  if (rd[0].record_type == GNUNET_DNSPARSER_TYPE_TXT)
+  {
+    did_document = (char *) rd[0].data;
+    cb (GNUNET_OK, did_document, cls_did_resolve_cb);
+  }
+  else
+    cb (GNUNET_NO, "DID Document is not a TXT record\n", cls_did_resolve_cb);
+}
+
+/**
+ * @brief Resolve a DID.
+ * Calls the given callback function with the resolved DID Document and the 
given closure.
+ * If the did can not be resolved did_document is NULL.
+ *
+ * @param did DID that is resolve
+ */
+enum GNUNET_GenericReturnValue
+DID_resolve (const char *did,
+             struct GNUNET_GNS_Handle *gns_handle,
+             DID_resolve_callback *cont,
+             void *cls)
+{
+  struct GNUNET_IDENTITY_PublicKey pkey;
+
+  // did, gns_handle and cont must me set
+  if ((did == NULL) || (gns_handle == NULL) || (cont == NULL))
+    return GNUNET_NO;
+
+  if (GNUNET_OK != DID_did_to_pkey (did, &pkey))
+    return GNUNET_NO;
+
+  // Create closure for lookup callback
+  struct DID_resolve_return *cls_gns_lookup_cb
+    = malloc (sizeof(struct DID_resolve_return));
+  cls_gns_lookup_cb->cb = cont;
+  cls_gns_lookup_cb->cls = cls;
+
+  GNUNET_GNS_lookup (gns_handle,
+                     DID_DOCUMENT_LABEL,
+                     &pkey,
+                     GNUNET_DNSPARSER_TYPE_TXT,
+                     GNUNET_GNS_LO_DEFAULT,
+                     &DID_resolve_gns_lookup_cb,
+                     cls_gns_lookup_cb);
+
+  return GNUNET_OK;
+}
+
+// ------------------------------------------------ //
+// -------------------- Create -------------------- //
+// ------------------------------------------------ //
+
+static void
+DID_create_did_store_cb (void *cls,
+                         int32_t success,
+                         const char *emsg)
+{
+  DID_action_callback *cb = ((struct DID_action_return *) cls)->cb;
+  void *cls_did_create_cb = ((struct DID_action_return *) cls)->cls;
+  free (cls);
+
+  if (GNUNET_OK == success)
+  {
+    cb (GNUNET_OK, (void *) cls_did_create_cb);
+  }
+  else
+  {
+    // TODO: Log emsg. Not writing it to STDOUT
+    printf ("%s\n", emsg);
+    cb (GNUNET_NO, (void *) cls_did_create_cb);
+  }
+}
+
+struct DID_create_namestore_lookup_closure
+{
+  const char *did_document;
+  struct GNUNET_TIME_Relative expire_time;
+  struct GNUNET_NAMESTORE_Handle *namestore_handle;
+  struct DID_action_return *ret;
+};
+
+static void
+DID_create_namestore_lookup_cb (void *cls,
+                                const struct
+                                GNUNET_IDENTITY_PrivateKey *zone,
+                                const char *label,
+                                unsigned int rd_count,
+                                const struct GNUNET_GNSRECORD_Data *rd)
+{
+  struct GNUNET_GNSRECORD_Data record_data;
+  struct GNUNET_IDENTITY_PublicKey pkey;
+
+  const char *did_document
+    = ((struct DID_create_namestore_lookup_closure *) cls)->did_document;
+
+  const struct GNUNET_TIME_Relative expire_time
+    = ((struct DID_create_namestore_lookup_closure *) cls)->expire_time;
+
+  struct GNUNET_NAMESTORE_Handle *namestore_handle
+    = ((struct DID_create_namestore_lookup_closure *) cls)->namestore_handle;
+
+  struct DID_action_return *cls_record_store_cb
+    = ((struct DID_create_namestore_lookup_closure *) cls)->ret;
+
+  free (cls);
+
+  if (rd_count > 0)
+  {
+    printf ("Ego already has a DID Document. Abort.\n");
+    cls_record_store_cb->cb (GNUNET_NO, cls_record_store_cb->cls);
+  }
+  else {
+    // Get public key
+    GNUNET_IDENTITY_key_get_public (zone, &pkey);
+
+    // If no DID Document is given a default one is created
+    if (did_document != NULL)
+      printf (
+        "DID Docuement is read from \"DID-document\" argument 
(EXPERIMENTAL)\n");
+    else
+      did_document = DID_pkey_to_did_document (&pkey);
+
+    // Create record
+    record_data.data = did_document;
+    record_data.expiration_time = expire_time.rel_value_us;
+    record_data.data_size = strlen (did_document) + 1;
+    record_data.record_type = GNUNET_GNSRECORD_typename_to_number ("TXT"),
+    record_data.flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION;
+
+    // Store record
+    GNUNET_NAMESTORE_records_store (namestore_handle,
+                                    zone,
+                                    DID_DOCUMENT_LABEL,
+                                    1, // FIXME what if 
GNUNET_GNS_EMPTY_LABEL_AT has records
+                                    &record_data,
+                                    &DID_create_did_store_cb,
+                                    (void *) cls_record_store_cb);
+  }
+}
+
+/**
+ * @brief Creates a DID and saves DID Document in Namestore.
+ *
+ * @param ego ego for which the DID should be created.
+ * @param did_document did_document that should be saved in namestore.
+ * If did_document==NULL -> Default DID document is created.
+ * @param namestore_handle
+ * @param cont callback function
+ * @param cls closure
+ */
+enum GNUNET_GenericReturnValue
+DID_create (const struct GNUNET_IDENTITY_Ego *ego,
+            const char *did_document,
+            const struct GNUNET_TIME_Relative *expire_time,
+            struct GNUNET_NAMESTORE_Handle *namestore_handle,
+            DID_action_callback *cont,
+            void *cls)
+{
+  struct GNUNET_IDENTITY_PublicKey pkey;
+
+  // Ego, namestore_handle and cont must be set
+  if ((ego == NULL) || (namestore_handle == NULL) || (cont == NULL))
+    return GNUNET_NO;
+
+  // Check if ego has EdDSA key
+  GNUNET_IDENTITY_ego_get_public_key ((struct GNUNET_IDENTITY_Ego *) ego,
+                                      &pkey);
+  if (ntohl (pkey.type) != GNUNET_GNSRECORD_TYPE_EDKEY)
+  {
+    printf ("The EGO has to have an EdDSA key pair\n");
+    return GNUNET_NO;
+  }
+
+  struct DID_action_return *ret
+    = malloc (sizeof(struct DID_action_return));
+  ret->cb = cont;
+  ret->cls = cls;
+
+  struct DID_create_namestore_lookup_closure *cls_name_store_lookup_cb
+    = malloc (sizeof(struct DID_create_namestore_lookup_closure));
+  cls_name_store_lookup_cb->did_document = did_document;
+  cls_name_store_lookup_cb->expire_time = (*expire_time);
+  cls_name_store_lookup_cb->namestore_handle = namestore_handle;
+  cls_name_store_lookup_cb->ret = ret;
+
+  // Check if ego already has a DID Document
+  GNUNET_NAMESTORE_records_lookup (namestore_handle,
+                                   GNUNET_IDENTITY_ego_get_private_key (ego),
+                                   DID_DOCUMENT_LABEL,
+                                   NULL,
+                                   NULL,
+                                   DID_create_namestore_lookup_cb,
+                                   (void *) cls_name_store_lookup_cb);
+
+  return GNUNET_OK;
+}
diff --git a/src/reclaim/did_core.h b/src/reclaim/did_core.h
new file mode 100644
index 000000000..842424e14
--- /dev/null
+++ b/src/reclaim/did_core.h
@@ -0,0 +1,138 @@
+/*
+   This file is part of GNUnet
+   Copyright (C) 2010-2015 GNUnet e.V.
+
+   GNUnet is free software: you can redistribute it and/or modify it
+   under the terms of the GNU Affero General Public License as published
+   by the Free Software Foundation, either version 3 of the License,
+   or (at your option) any later version.
+
+   GNUnet is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Affero General Public License for more details.
+
+   You should have received a copy of the GNU Affero General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+   SPDX-License-Identifier: AGPL3.0-or-later
+ */
+
+/**
+ * @file reclaim/did_core.h
+ * @brief Core functionality for GNUNET Decentralized Identifier
+ * @author Tristan Schwieren
+ */
+
+#include "platform.h"
+#include "gnunet_util_lib.h"
+#include "gnunet_namestore_service.h"
+#include "gnunet_gns_service.h"
+#include "gnunet_gnsrecord_lib.h"
+#include "gnunet_identity_service.h"
+#include "did_helper.h"
+#include "jansson.h"
+
+// #define DID_DOCUMENT_LABEL GNUNET_GNS_EMPTY_LABEL_AT
+#define DID_DOCUMENT_LABEL "didd"
+#define DID_DOCUMENT_DEFAULT_EXPIRATION_TIME "365d"
+
+/**
+ * @brief Signature of a callback function that is called after a did has been 
resolved.
+ * did_document contains an Error message if DID can not be resolved.
+ * Calls the given callback function with the resolved DID Document and the 
given closure.
+ * If the did can not be resolved did_document is NULL.
+ * @param status Equals GNUNET_OK if DID Docuemnt has been resolved
+ * @param did_document resolved DID Document
+ * @param cls previsouly given closure
+ */
+typedef void
+  DID_resolve_callback (enum GNUNET_GenericReturnValue status, char 
*did_document, void *cls);
+
+/**
+ * @brief Signature of a callback function that is called after a did has been 
removed
+ * status = 0 if action was sucessfull
+ * status = 1 if action failed
+ *
+ * @param status status of the perfermormed action.
+ * @param cls previsouly given closure
+ */
+typedef void
+  DID_action_callback (enum GNUNET_GenericReturnValue status, void *cls);
+
+
+/**
+ * @brief Resolve a DID.
+ * Calls the given callback function with the resolved DID Document and the 
given closure.
+ * If the did can not be resolved did_document is NULL.
+ *
+ * @param did DID that is resolved
+ * @param gns_handle pointer to gns handle.
+ * @param cont callback function
+ * @param cls closure
+ */
+enum GNUNET_GenericReturnValue
+DID_resolve (const char *did,
+             struct GNUNET_GNS_Handle *gns_handle,
+             DID_resolve_callback *cont,
+             void *cls);
+
+
+/**
+ * @brief Removes the DID Document from namestore.
+ * Ego is not removed.
+ * Calls the callback function with status and the given closure.
+ *
+ * @param ego ego which controlls the DID
+ * @param cfg_handle pointer to configuration handle
+ * @param namestore_handle pointer to namestore handle
+ * @param cont callback function
+ * @param cls closure
+ */
+enum GNUNET_GenericReturnValue
+DID_remove (const struct GNUNET_IDENTITY_Ego *ego,
+            struct GNUNET_CONFIGURATION_Handle *cfg_handle,
+            struct GNUNET_NAMESTORE_Handle *namestore_handle,
+            DID_action_callback *cont,
+            void *cls);
+
+
+/**
+ * @brief Creates a DID and saves DID Document in Namestore.
+ *
+ * @param ego ego for which the DID should be created.
+ * @param did_document did_document that should be saved in namestore.
+ * If did_document==NULL -> Default DID document is created.
+ * @param expire_time 
+ * @param namestore_handle
+ * @param cont callback function
+ * @param cls closure
+ */
+enum GNUNET_GenericReturnValue
+DID_create (const struct GNUNET_IDENTITY_Ego *ego,
+            const char *did_document,
+            const struct GNUNET_TIME_Relative *expire_time,
+            struct GNUNET_NAMESTORE_Handle *namestore_handle,
+            DID_action_callback *cont,
+            void *cls);
+
+
+/**
+ * @brief Replace the DID Document of a DID.
+ *
+ * @param ego ego for which the DID Document should be replaced
+ * @param did_document new DID Document
+ * @param cfg_handle pointer to configuration handle
+ * @param identity_handle pointer to configuration handle
+ * @param namestore_handle pointer to namestore handle
+ * @param cont callback function
+ * @param cls closure
+ */
+enum GNUNET_GenericReturnValue
+DID_replace (struct GNUNET_IDENTITY_Ego *ego,
+             char *did_document,
+             const struct GNUNET_CONFIGURATION_Handle *cfg_handle,
+             struct GNUNET_IDENTITY_Handle *identity_handle,
+             struct GNUNET_NAMESTORE_Handle *namestore_handle,
+             DID_action_callback *cont,
+             void *cls);
diff --git a/src/reclaim/did_helper.c b/src/reclaim/did_helper.c
new file mode 100644
index 000000000..1c04ede33
--- /dev/null
+++ b/src/reclaim/did_helper.c
@@ -0,0 +1,203 @@
+/*
+   This file is part of GNUnet
+   Copyright (C) 2010-2015 GNUnet e.V.
+
+   GNUnet is free software: you can redistribute it and/or modify it
+   under the terms of the GNU Affero General Public License as published
+   by the Free Software Foundation, either version 3 of the License,
+   or (at your option) any later version.
+
+   GNUnet is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Affero General Public License for more details.
+
+   You should have received a copy of the GNU Affero General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+   SPDX-License-Identifier: AGPL3.0-or-later
+ */
+
+/**
+ * @file reclaim/did_helper.c
+ * @brief helper library for DID related functions
+ * @author Tristan Schwieren
+ */
+#include "platform.h"
+#include "gnunet_util_lib.h"
+#include "gnunet_namestore_service.h"
+#include "gnunet_gns_service.h"
+#include "gnunet_gnsrecord_lib.h"
+#include "did_helper.h"
+#include "jansson.h"
+
+#define STR_INDIR(x) #x
+#define STR(x) STR_INDIR (x)
+
+/**
+ * @brief Generate a DID for a given GNUNET public key
+ *
+ * @param pkey
+ * @return char* Returns the DID. Caller must free
+ * TODO: Check if EdDSA
+ */
+char*
+DID_pkey_to_did (struct GNUNET_IDENTITY_PublicKey *pkey)
+{
+  char *pkey_str;
+  char *did_str;
+
+  pkey_str = GNUNET_IDENTITY_public_key_to_string (pkey);
+  GNUNET_asprintf (&did_str, "%s%s",
+                   GNUNET_DID_METHOD_PREFIX,
+                   pkey_str);
+
+  GNUNET_free (pkey_str);
+  return did_str;
+}
+
+/**
+ * @brief Generate a DID for a given gnunet EGO.
+ * Wrapper around GNUNET_DID_pkey_to_did
+ *
+ * @param ego
+ * @return char* Returns the DID. Caller must free
+ */
+char*
+DID_identity_to_did (struct GNUNET_IDENTITY_Ego *ego)
+{
+  struct GNUNET_IDENTITY_PublicKey pkey;
+
+  GNUNET_IDENTITY_ego_get_public_key (ego, &pkey);
+  return DID_pkey_to_did (&pkey);
+}
+
+/**
+ * @brief Return the public key of a DID
+ */
+enum GNUNET_GenericReturnValue
+DID_did_to_pkey (const char *did, struct GNUNET_IDENTITY_PublicKey *pkey)
+{
+  char pkey_str[MAX_DID_SPECIFIC_IDENTIFIER_LENGTH];
+
+  if ((1 != (sscanf (did,
+                     GNUNET_DID_METHOD_PREFIX "%"
+                     STR (MAX_DID_SPECIFIC_IDENTIFIER_LENGTH)
+                     "s", pkey_str))) ||
+      (GNUNET_OK != GNUNET_IDENTITY_public_key_from_string (pkey_str, pkey)))
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Could not decode given DID: %s\n",
+                did);
+    return GNUNET_NO;
+  }
+
+  return GNUNET_OK;
+}
+
+/**
+ * @brief Convert a base 64 encoded public key to a GNUNET key
+ */
+struct GNUNET_IDENTITY_PublicKey *
+GNUNET_DID_key_covert_multibase_base64_to_gnunet (char *pkey_str)
+{
+  return NULL;
+}
+
+/**
+ * @brief Convert GNUNET key to a base 64 encoded public key
+ */
+char *
+DID_key_covert_gnunet_to_multibase_base64 (struct
+                                           GNUNET_IDENTITY_PublicKey *
+                                           pkey)
+{
+  struct GNUNET_CRYPTO_EddsaPublicKey pubkey = pkey->eddsa_key;
+
+  // This is how to convert out pubkeys to W3c Ed25519-2020 multibase 
(base64url no padding)
+  char *pkey_base_64;
+  char *pkey_multibase;
+  char pkx[34];
+
+  pkx[0] = 0xed;
+  pkx[1] = 0x01;
+  memcpy (pkx + 2, &pubkey, sizeof (pubkey));
+  GNUNET_STRINGS_base64url_encode (pkx, sizeof (pkx), &pkey_base_64);
+  GNUNET_asprintf (&pkey_multibase, "u%s", pkey_base_64);
+
+  GNUNET_free (pkey_base_64);
+  return pkey_multibase;
+}
+
+/**
+ * @brief Create a did generate did object
+ *
+ * @param pkey
+ * @return void* Return pointer to the DID Document
+ */
+char *
+DID_pkey_to_did_document (struct GNUNET_IDENTITY_PublicKey *pkey)
+{
+
+  /* FIXME-MSC: This is effectively creating a DID Document default template 
for
+   * the initial document.
+   * Maybe this can be refactored to generate such a template for an identity?
+   * Even if higher layers add/modify it, there should probably still be a
+   * GNUNET_DID_document_template_from_identity()
+   */
+
+  char *did_str;
+  char *verify_id_str;
+  char *pkey_multibase_str;
+  char *didd_str;
+  json_t *didd_json;
+
+  did_str = DID_pkey_to_did (pkey);
+  GNUNET_asprintf (&verify_id_str, "%s#key-1", did_str);
+
+  pkey_multibase_str = DID_key_covert_gnunet_to_multibase_base64 (pkey);
+
+  didd_json = json_pack (
+    "{s:[ss], s:s, s:[{s:s, s:s, s:s, s:s}], s:[s], s:[s]}",
+    "@context",
+    "https://www.w3.org/ns/did/v1";,
+    "https://w3id.org/security/suites/ed25519-2020/v1";,
+    "id",
+    did_str,
+    "verificationMethod",
+    "id",
+    verify_id_str,
+    "type",
+    "Ed25519VerificationKey2020",
+    "controller",
+    did_str,
+    "publicKeyMultibase",
+    pkey_multibase_str,
+    "authentication",
+    "#key-1",
+    "assertionMethod",
+    "#key-1");
+
+  // Encode DID Document as JSON string
+  didd_str = json_dumps (didd_json, JSON_INDENT (2));
+
+  // Free
+  GNUNET_free (did_str);
+  GNUNET_free (verify_id_str);
+  GNUNET_free (pkey_multibase_str);
+  json_decref (didd_json);
+
+  return didd_str;
+}
+
+/**
+ * @brief Generate the default DID document for a GNUNET ego
+ * Wrapper around GNUNET_DID_pkey_to_did_document
+ */
+char *
+DID_identity_to_did_document (struct GNUNET_IDENTITY_Ego *ego)
+{
+  struct GNUNET_IDENTITY_PublicKey pkey;
+
+  GNUNET_IDENTITY_ego_get_public_key (ego, &pkey);
+  return DID_pkey_to_did (&pkey);
+}
\ No newline at end of file
diff --git a/src/reclaim/did_helper.h b/src/reclaim/did_helper.h
new file mode 100644
index 000000000..c3ee457af
--- /dev/null
+++ b/src/reclaim/did_helper.h
@@ -0,0 +1,74 @@
+/*
+   This file is part of GNUnet
+   Copyright (C) 2010-2015 GNUnet e.V.
+
+   GNUnet is free software: you can redistribute it and/or modify it
+   under the terms of the GNU Affero General Public License as published
+   by the Free Software Foundation, either version 3 of the License,
+   or (at your option) any later version.
+
+   GNUnet is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Affero General Public License for more details.
+
+   You should have received a copy of the GNU Affero General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+   SPDX-License-Identifier: AGPL3.0-or-later
+ */
+
+/**
+ * @file reclaim/did_helper.h
+ * @brief helper library for DID related functions
+ * @author Tristan Schwieren
+ */
+
+#define GNUNET_DID_METHOD_PREFIX "did:reclaim:"
+#define MAX_DID_SPECIFIC_IDENTIFIER_LENGTH 59
+
+/**
+ * @brief Return a DID for a given GNUNET public key
+ */
+char *
+DID_pkey_to_did (struct GNUNET_IDENTITY_PublicKey *pkey);
+
+/**
+ * @brief Generate a DID for a given gnunet EGO
+ *
+ * @param ego
+ * @return char * Returns the DID. Caller must free
+ */
+char *
+DID_identity_to_did (struct GNUNET_IDENTITY_Ego *ego);
+
+/**
+ * @brief Return the public key of a DID
+ */
+enum GNUNET_GenericReturnValue
+DID_did_to_pkey (const char *did, struct GNUNET_IDENTITY_PublicKey *pkey);
+
+// /**
+//  * @brief Convert a base 64 encoded public key to a GNUNET key
+//  */
+// struct GNUNET_IDENTITY_PublicKey *
+// GNUNET_DID_key_covert_multibase_base64_to_gnunet(char *);
+
+/**
+ * @brief Convert GNUNET key to a base 64 encoded public key
+ */
+char *
+DID_key_covert_gnunet_to_multibase_base64 (struct
+                                                  GNUNET_IDENTITY_PublicKey *);
+
+/**
+ * @brief Generate the default DID document for a GNUNET public key
+ */
+char *
+DID_pkey_to_did_document (struct GNUNET_IDENTITY_PublicKey *pkey);
+
+/**
+ * @brief Generate the default DID document for a GNUNET ego
+ */
+char *
+DID_identity_to_did_document (struct GNUNET_IDENTITY_Ego *ego);
\ No newline at end of file
diff --git a/src/reclaim/gnunet-did.c b/src/reclaim/gnunet-did.c
index 4c5704d44..6f802aded 100644
--- a/src/reclaim/gnunet-did.c
+++ b/src/reclaim/gnunet-did.c
@@ -36,10 +36,12 @@
 #include "platform.h"
 #include "gnunet_util_lib.h"
 #include "gnunet_namestore_service.h"
+#include "gnunet_identity_service.h"
 #include "gnunet_gns_service.h"
 #include "gnunet_gnsrecord_lib.h"
+#include "did_helper.h"
+#include "did_core.h"
 #include "jansson.h"
-#include "did.h"
 
 #define GNUNET_DID_DEFAULT_DID_DOCUMENT_EXPIRATION_TIME "1d"
 
@@ -146,73 +148,6 @@ cleanup (void *cls)
   GNUNET_SCHEDULER_shutdown ();
 }
 
-/**
- * @brief Callback for ego loockup of get_did_for_ego()
- *
- * @param cls closure
- * @param ego the returned ego
- */
-static void
-get_did_for_ego_lookup_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego)
-{
-  char *did_str;
-
-  if (ego == NULL)
-  {
-    printf ("EGO not found\n");
-    GNUNET_SCHEDULER_add_now (&cleanup, NULL);
-    ret = 1;
-    return;
-  }
-  did_str = DID_ego_to_did (ego);
-
-  printf ("%s\n", did_str);
-
-  GNUNET_SCHEDULER_add_now (&cleanup, NULL);
-  ret = 0;
-  return;
-}
-
-/**
- * @brief Get the DID for a given EGO
- *
- */
-static void
-get_did_for_ego ()
-{
-  if (egoname != NULL)
-  {
-    GNUNET_IDENTITY_ego_lookup (my_cfg,
-                                egoname,
-                                &get_did_for_ego_lookup_cb,
-                                NULL);
-  }
-  else {
-    printf ("Set the EGO argument to get the DID for a given EGO\n");
-    GNUNET_SCHEDULER_add_now (&cleanup, NULL);
-    ret = 1;
-    return;
-  }
-}
-
-
-/**
- * @brief Get the public key from did attribute given by the user
- *
- * @param pkey place to write the public key to
- */
-static void
-get_pkey_from_attr_did (struct GNUNET_IDENTITY_PublicKey *pkey)
-{
-  if (GNUNET_OK != DID_public_key_from_did (did, pkey))
-  {
-    fprintf (stderr, _("Invalid DID `%s'\n"), did);
-    GNUNET_SCHEDULER_add_now (cleanup, NULL);
-    ret = 1;
-    return;
-  }
-}
-
 /**
  * @brief GNS lookup callback. Prints the DID Document to standard out.
  * Fails if there is more than one DID record.
@@ -223,32 +158,17 @@ get_pkey_from_attr_did (struct GNUNET_IDENTITY_PublicKey 
*pkey)
  */
 static void
 print_did_document (
-  void *cls,
-  uint32_t rd_count,
-  const struct GNUNET_GNSRECORD_Data *rd)
+  enum GNUNET_GenericReturnValue status,
+  char *did_document,
+  void *cls
+  )
 {
-  /*
-   * FIXME-MSC: The user may decide to put other records here.
-   * In general I am fine with the constraint here, but not when
-   * we move it to "@"
-   */
-  if (rd_count != 1)
-  {
-    printf ("An ego should only have one DID Document\n");
-    GNUNET_SCHEDULER_add_now (cleanup, NULL);
-    ret = 1;
-    return;
-  }
-
-  if (rd[0].record_type == GNUNET_DNSPARSER_TYPE_TXT)
-  {
-    printf ("%s\n", (char *) rd[0].data);
-  }
-  else {
-    printf ("DID Document is not a TXT record\n");
-  }
+  if (GNUNET_OK == status)
+    printf ("%s\n", did_document);
+  else
+    printf ("An error occured: %s\n", did_document);
 
-  GNUNET_SCHEDULER_add_now (&cleanup, NULL);
+  GNUNET_SCHEDULER_add_now (cleanup, NULL);
   ret = 0;
   return;
 }
@@ -257,7 +177,7 @@ print_did_document (
  * @brief Resolve a DID given by the user.
  */
 static void
-resolve_did_document ()
+resolve_did ()
 {
   struct GNUNET_IDENTITY_PublicKey pkey;
 
@@ -269,10 +189,13 @@ resolve_did_document ()
     return;
   }
 
-  get_pkey_from_attr_did (&pkey);
-
-  GNUNET_GNS_lookup (gns_handle, GNUNET_GNS_EMPTY_LABEL_AT, &pkey, 
GNUNET_DNSPARSER_TYPE_TXT,
-                     GNUNET_GNS_LO_DEFAULT, &print_did_document, NULL);
+  if (GNUNET_OK != DID_resolve (did, gns_handle, print_did_document, NULL))
+  {
+    printf ("An error occured while resoling the DID\n");
+    GNUNET_SCHEDULER_add_now (cleanup, NULL);
+    ret = 0;
+    return;
+  }
 }
 
 
@@ -320,7 +243,8 @@ remove_did_document_namestore_cb (void *cls, int32_t 
success, const char *emgs)
       ret = 0;
       return;
     }
-  } else {
+  }
+  else {
     printf ("Something went wrong when deleting the DID Document\n");
 
     if (emgs != NULL)
@@ -328,7 +252,7 @@ remove_did_document_namestore_cb (void *cls, int32_t 
success, const char *emgs)
       printf ("%s\n", emgs);
     }
 
-    GNUNET_SCHEDULER_add_now (&cleanup, NULL);
+    GNUNET_SCHEDULER_add_now (cleanup, NULL);
     ret = 0;
     return;
   }
@@ -382,259 +306,123 @@ remove_did_document (remove_did_document_callback cont, 
void *cls)
   }
 }
 
+// Needed because create_did_ego_lookup_cb() and
+// create_did_ego_create_cb() can call each other
+static void create_did_ego_lockup_cb ();
 
 /**
- * @brief Create a did generate did object
+ * @brief Create a DID(-Document). Called after DID has been created
+ * Prints status and the DID.
  *
- * @param pkey
- * @return void* Return pointer to the DID Document
  */
-char *
-create_did_generate (struct GNUNET_IDENTITY_PublicKey pkey)
+static void
+create_did_cb (enum GNUNET_GenericReturnValue status, void *cls)
 {
-  /* FIXME-MSC: I would prefer constants instead of magic numbers */
-  char *pkey_str;  // Convert public key to string
-  char did_str[71]; // 58 + 12 + 1 = 71
-  char *didd_str;
-  char verify_id_str[77]; // did_str len + "#key-1" = 71 + 6 = 77
-  char *pkey_multibase_str;
-
-  /* FIXME-MSC: This screams for a GNUNET_DID_identity_key_to_string() */
-  char *b64;
-  char pkx[34];
-  pkx[0] = 0xed;
-  pkx[1] = 0x01;
-  memcpy (pkx + 2, &(pkey.eddsa_key), sizeof(pkey.eddsa_key));
-  GNUNET_STRINGS_base64_encode (pkx, sizeof(pkx), &b64);
-
-  GNUNET_asprintf (&pkey_multibase_str, "u%s", b64);
-
-  json_t *didd;
-  json_t *did_json;
-  json_t *pkey_multibase_json;
-  json_t *context_json;
-  json_t *context_1_json;
-  json_t *context_2_json;
-  json_t *verify_json;
-  json_t *verify_1_json;
-  json_t *verify_1_type_json;
-  json_t *verify_1_id_json;
-  json_t *verify_relative_ref_json;
-  json_t *auth_json;
-  json_t *assert_json;
-
-  /* FIXME-MSC: This screams for GNUNET_DID_identity_to_did() */
-  pkey_str = GNUNET_IDENTITY_public_key_to_string (&pkey); // Convert public 
key to string
-  sprintf (did_str, "did:reclaim:%s", pkey_str); // Convert the public key to 
a DID str
-  sprintf (verify_id_str, "did:reclaim:%s#key-1", pkey_str); // Convert the 
public key to a DID str
-
-  // sprintf(pkey_multibase_str, "V%s", pkey_str); // Convert the public key 
to MultiBase data format
-
-  /* FIXME-MSC: This is effectively creating a DID Document default template 
for
-   * the initial document.
-   * Maybe this can be refactored to generate such a template for an identity?
-   * Even if higher layers add/modify it, there should probably still be a
-   * GNUNET_DID_document_template_from_identity()
-   */
-  // Create Json Strings
-  did_json = json_string (did_str);
-  pkey_multibase_json = json_string (pkey_multibase_str);
-
-  context_1_json = json_string ("https://www.w3.org/ns/did/v1";);
-  context_2_json = json_string (
-    "https://w3id.org/security/suites/ed25519-2020/v1";);
-  verify_1_id_json = json_string (verify_id_str);
-  verify_1_type_json = json_string ("Ed25519VerificationKey2020");
-
-  // Add a relative DID URL to reference a verifiation method
-  // https://www.w3.org/TR/did-core/#relative-did-urls`
-  verify_relative_ref_json = json_string ("#key-1");
-
-  // Create DID Document
-  didd = json_object ();
-
-  // Add context
-  context_json = json_array ();
-  json_array_append (context_json, context_1_json);
-  json_array_append (context_json, context_2_json);
-  json_object_set (didd, "@context", context_json);
-
-  // Add id
-  json_object_set (didd, "id", did_json);
-
-  // Add verification method
-  verify_json = json_array ();
-  verify_1_json = json_object ();
-  json_object_set (verify_1_json, "id", verify_1_id_json);
-  json_object_set (verify_1_json, "type", verify_1_type_json);
-  json_object_set (verify_1_json, "controller", did_json);
-  json_object_set (verify_1_json, "publicKeyMultiBase", pkey_multibase_json);
-  json_array_append (verify_json, verify_1_json);
-  json_object_set (didd, "verificationMethod", verify_json);
-
-  // Add authentication method
-  auth_json = json_array ();
-  json_array_append (auth_json, verify_relative_ref_json);
-  json_object_set (didd, "authentication", auth_json);
-
-  // Add assertion method to issue a Verifiable Credential
-  assert_json = json_array ();
-  json_array_append (assert_json, verify_relative_ref_json);
-  json_object_set (didd, "assertionMethod", assert_json);
-
-  // Encode DID Document as JSON string
-  didd_str = json_dumps (didd, JSON_INDENT (2));
-  if (didd_str == NULL)
+  if (GNUNET_OK == status)
   {
-    printf ("DID Document could not be encoded");
-    GNUNET_SCHEDULER_add_now (&cleanup, NULL);
+    printf ("DID has been created.\n%s\n", (char *) cls);
+    free (cls);
+    ret = 0;
+  }
+  else
+  {
+    printf ("An error occured while creating the DID.\n");
     ret = 1;
-    return NULL;
   }
 
-  // TODO: MORE FREEEEEEEE
-  /* FIXME-MSC: json_t's are free'd using "json_decref". Also json_t usually
-   * keeps a reference counter. Check jansson docs for how to use it.
-   * Also: Use valgrind to find leaks.
-   */
-  free (pkey_multibase_str);
-  free (b64);
-
-  free (didd);
-  free (did_json);
-  free (pkey_multibase_json);
-  free (context_json);
-  free (context_1_json);
-  free (context_2_json);
-  free (verify_json);
-  free (verify_1_json);
-  free (verify_1_type_json);
-  free (verify_1_id_json);
-  free (auth_json);
-  free (assert_json);
-  free (verify_relative_ref_json);
-
-  return didd_str;
-}
-
-/**
- * @brief Create a DID. Store DID in Namestore cb
- *
- */
-static void
-create_did_store_cb (void *cls, int32_t success, const char *emsg)
-{
   GNUNET_SCHEDULER_add_now (&cleanup, NULL);
-  ret = 0;
   return;
 }
 
 /**
- * @brief Create a did. Store DID in Namestore
- *
- * @param didd_str String endoced DID Docuement
- * @param ego Identity whos DID Document is stored
+ * @brief Create a DID(-Document) - Called after a new Identity has been 
created.
  */
 static void
-create_did_store (char *didd_str, struct GNUNET_IDENTITY_Ego *ego)
+create_did_ego_create_cb (void *cls,
+                          const struct GNUNET_IDENTITY_PrivateKey *pk,
+                          const char *emsg)
 {
-
-  struct GNUNET_TIME_Relative expire_time;
-  struct GNUNET_GNSRECORD_Data record_data;
-  const struct GNUNET_IDENTITY_PrivateKey *skey;
-
-  if (GNUNET_STRINGS_fancy_time_to_relative ((NULL != expire) ?
-                                             expire :
-                                             
GNUNET_DID_DEFAULT_DID_DOCUMENT_EXPIRATION_TIME,
-                                             &expire_time) == GNUNET_OK)
+  if (emsg != NULL)
   {
-    record_data.data = didd_str;
-    record_data.expiration_time = expire_time.rel_value_us;
-    record_data.data_size = strlen (didd_str) + 1;
-    record_data.record_type = GNUNET_GNSRECORD_typename_to_number ("TXT"),
-    record_data.flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION;
-
-    skey = GNUNET_IDENTITY_ego_get_private_key (ego);
-
-    GNUNET_NAMESTORE_records_store (namestore_handle,
-                                    skey,
-                                    GNUNET_GNS_EMPTY_LABEL_AT,
-                                    1, //FIXME what if 
GNUNET_GNS_EMPTY_LABEL_AT has records
-                                    &record_data,
-                                    &create_did_store_cb,
-                                    NULL);
-  }
-  else {
-    printf ("Failed to read given expiration time\n");
+    printf ("%s\n", emsg);
     GNUNET_SCHEDULER_add_now (&cleanup, NULL);
     ret = 1;
     return;
   }
+
+  GNUNET_IDENTITY_ego_lookup (my_cfg,
+                              egoname,
+                              &create_did_ego_lockup_cb,
+                              NULL);
 }
 
 /**
- * @brief Create a did ego lockup cb
+ * @brief Create a DID(-Document). Called after ego lookup
  *
- * @param cls
- * @param ego
  */
 static void
 create_did_ego_lockup_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego)
 {
-  struct GNUNET_IDENTITY_PublicKey pkey;
-  char *didd_str;
-
   if (ego == NULL)
   {
-    printf ("EGO not found\n");
-    GNUNET_SCHEDULER_add_now (&cleanup, NULL);
-    ret = 1;
-    return;
-  }
-
-  GNUNET_IDENTITY_ego_get_public_key (ego, &pkey);
-
-  if (ntohl (pkey.type) != GNUNET_GNSRECORD_TYPE_EDKEY)
-  {
-    printf ("The EGO has to have an EDDSA key pair\n");
-    GNUNET_SCHEDULER_add_now (&cleanup, NULL);
-    ret = 1;
-    return;
+    // If Ego was not found. Create new one first
+    printf ("Ego was not found. Creating new one.\n");
+    GNUNET_IDENTITY_create (identity_handle,
+                            egoname,
+                            NULL,
+                            GNUNET_IDENTITY_TYPE_EDDSA,
+                            &create_did_ego_create_cb,
+                            egoname);
   }
-
-  if (didd != NULL)
+  else
   {
-    printf (
-      "DID Docuement is read from \"did-document\" argument (EXPERIMENTAL)\n");
-    didd_str = strdup (didd);
-  }
-  else {
-    // Generate DID Docuement from public key
-    didd_str = create_did_generate (pkey);
-  }
-
-  // Print DID Document to stdout
-  printf ("%s\n", didd_str);
+    char *did = DID_identity_to_did (ego);
+    void *cls = malloc (strlen (did) + 1);
+    struct GNUNET_TIME_Relative expire_relative;
 
-  // Store the DID Document
-  create_did_store (didd_str, ego);
+    if (expire == NULL)
+    {
+      GNUNET_STRINGS_fancy_time_to_relative (
+        DID_DOCUMENT_DEFAULT_EXPIRATION_TIME, &expire_relative);
+    }
+    else if (GNUNET_OK != GNUNET_STRINGS_fancy_time_to_relative (expire,
+                                                                 &
+                                                                 
expire_relative))
+    {
+      printf ("Failed to read given expiration time\n");
+      GNUNET_SCHEDULER_add_now (cleanup, NULL);
+      ret = 1;
+      return;
+    }
 
-  // Save DID Document String to GNS
-  free (didd_str);
+    strcpy (cls, did);
+    // TODO: Add DID_document argument
+    if (GNUNET_OK != DID_create (ego,
+                                 NULL,
+                                 &expire_relative,
+                                 namestore_handle,
+                                 create_did_cb,
+                                 cls))
+    {
+      printf ("An error occured while creating the DID.\n");
+      ret = 1;
+      GNUNET_SCHEDULER_add_now (&cleanup, NULL);
+      return;
+    }
+  }
 }
 
 /**
- * @brief Create a did document - Create a new identity first
+ * @brief Create a DID(-Document).
+ *
  */
 static void
-create_did_document_ego_create_cb (void *cls,
-                                   const struct GNUNET_IDENTITY_PrivateKey *pk,
-                                   const char *emsg)
+create_did ()
 {
-
-  if (emsg != NULL)
+  // Ego name to be set
+  if (egoname == NULL)
   {
-    printf ("%s\n", emsg);
+    printf ("Set the Ego argument to create a new DID(-Document)\n");
     GNUNET_SCHEDULER_add_now (&cleanup, NULL);
     ret = 1;
     return;
@@ -646,31 +434,6 @@ create_did_document_ego_create_cb (void *cls,
                               NULL);
 }
 
-/**
- * @brief Create a did document
- *
- */
-static void
-create_did_document ()
-{
-  if ((egoname != NULL) && (expire != NULL))
-  {
-    GNUNET_IDENTITY_create (identity_handle,
-                            egoname,
-                            NULL,
-                            GNUNET_IDENTITY_TYPE_EDDSA,
-                            &create_did_document_ego_create_cb,
-                            egoname);
-  }
-  else {
-    printf (
-      "Set the EGO and the Expiration-time argument to create a new 
DID(-Document)\n");
-    GNUNET_SCHEDULER_add_now (&cleanup, NULL);
-    ret = 1;
-    return;
-  }
-}
-
 
 /**
  * @brief Replace a DID Docuemnt. Callback function after ego lockup
@@ -681,7 +444,7 @@ create_did_document ()
 static void
 replace_did_document_ego_lookup_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego)
 {
-  create_did_store (didd, ego);
+  // create_did_store (didd, ego);
 }
 
 /**
@@ -721,13 +484,15 @@ replace_did_document ()
 static void
 post_ego_iteration (void *cls)
 {
+  // TODO: Check that only one argument is set
+
   if (1 == replace)
   {
     replace_did_document ();
   }
   else if (1 == get)
   {
-    resolve_did_document ();
+    resolve_did ();
   }
   else if (1 == remove_did)
   {
@@ -735,7 +500,7 @@ post_ego_iteration (void *cls)
   }
   else if (1 == create)
   {
-    create_did_document ();
+    create_did ();
   }
   else {
     // No Argument found
@@ -760,19 +525,21 @@ process_dids (void *cls, struct GNUNET_IDENTITY_Ego *ego,
     GNUNET_SCHEDULER_add_now (&post_ego_iteration, NULL);
     return;
   }
-  if (NULL == name)
-    return;
-  if ((1 == create) &&
-      (0 == strncmp (name, egoname, strlen (egoname))) &&
-      (1 != ego_exists))
-  {
-    fprintf(stderr, "%s already exists!\n", egoname);
-    ego_exists = 1;
-    return;
-  }
+
+  // if (NULL == name)
+  //   return;
+  // if ((1 == create) &&
+  //     (0 == strncmp (name, egoname, strlen (egoname))) &&
+  //     (1 != ego_exists))
+  // {
+  //   fprintf (stderr, "%s already exists!\n", egoname);
+  //   ego_exists = 1;
+  //   return;
+  // }
+
   if (1 == show_all)
   {
-    did_str = DID_ego_to_did (ego);
+    did_str = DID_identity_to_did (ego);
     printf ("%s\n", did_str);
     GNUNET_free (did_str);
     return;
@@ -781,7 +548,7 @@ process_dids (void *cls, struct GNUNET_IDENTITY_Ego *ego,
   {
     if (0 == strncmp (name, egoname, strlen (egoname)))
     {
-      did_str = DID_ego_to_did (ego);
+      did_str = DID_identity_to_did (ego);
       printf ("%s\n", did_str);
       GNUNET_free (did_str);
       return;
@@ -839,10 +606,6 @@ main (int argc, char *const argv[])
                                gettext_noop (
                                  "Get the DID Document associated with the 
given DID"),
                                &get),
-    GNUNET_GETOPT_option_flag ('s',
-                               "show",
-                               gettext_noop ("Show the DID for a given ego"),
-                               &show),
     GNUNET_GETOPT_option_flag ('r',
                                "remove",
                                gettext_noop (
@@ -852,9 +615,13 @@ main (int argc, char *const argv[])
                                "replace",
                                gettext_noop ("Replace the DID Document."),
                                &replace),
+    GNUNET_GETOPT_option_flag ('s',
+                               "show",
+                               gettext_noop ("Show the DID for a given ego"),
+                               &show),
     GNUNET_GETOPT_option_flag ('A',
-                               "--show-all",
-                               gettext_noop ("Replace the DID Document."),
+                               "show-all",
+                               gettext_noop ("Show egos with DIDs"),
                                &show_all),
     GNUNET_GETOPT_option_string ('d',
                                  "did",
@@ -863,7 +630,7 @@ main (int argc, char *const argv[])
                                    "The Decentralized Identity (DID)"),
                                  &did),
     GNUNET_GETOPT_option_string ('D',
-                                 "--did-document",
+                                 "did-document",
                                  "JSON",
                                  gettext_noop (
                                    "The DID Document to store in GNUNET"),
@@ -885,8 +652,7 @@ main (int argc, char *const argv[])
   if (GNUNET_OK != GNUNET_PROGRAM_run (argc,
                                        argv,
                                        "gnunet-did",
-                                       _ (
-                                         "Manage Decentralized Identities 
(DIDs)"),
+                                       "Manage Decentralized Identities 
(DIDs)",
                                        options,
                                        &run,
                                        NULL))
diff --git a/src/reclaim/test_did_helper.c b/src/reclaim/test_did_helper.c
new file mode 100644
index 000000000..2f72c3496
--- /dev/null
+++ b/src/reclaim/test_did_helper.c
@@ -0,0 +1,131 @@
+/*
+   This file is part of GNUnet
+   Copyright (C) 2010-2015 GNUnet e.V.
+
+   GNUnet is free software: you can redistribute it and/or modify it
+   under the terms of the GNU Affero General Public License as published
+   by the Free Software Foundation, either version 3 of the License,
+   or (at your option) any later version.
+
+   GNUnet is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Affero General Public License for more details.
+
+   You should have received a copy of the GNU Affero General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+   SPDX-License-Identifier: AGPL3.0-or-later
+ */
+
+/**
+ * @file reclaim/test_did_helper.c
+ * @brief Unit tests for the helper library for DID related functions
+ * @author Tristan Schwieren
+ */
+
+#include "platform.h"
+#include "gnunet_util_lib.h"
+#include "gnunet_namestore_service.h"
+#include "gnunet_gns_service.h"
+#include "gnunet_gnsrecord_lib.h"
+#include "did_helper.h"
+#include "jansson.h"
+
+static const char test_skey_bytes[32] = {
+  0x9b, 0x93, 0x7b, 0x81, 0x32, 0x2d, 0x81, 0x6c,
+  0xfa, 0xb9, 0xd5, 0xa3, 0xba, 0xac, 0xc9, 0xb2,
+  0xa5, 0xfe, 0xbe, 0x4b, 0x14, 0x9f, 0x12, 0x6b,
+  0x36, 0x30, 0xf9, 0x3a, 0x29, 0x52, 0x70, 0x17
+};
+
+// TODO: Create a did manual from private key / independet of implementation
+static const char *test_did =
+  "did:reclaim:000G0509BYD1MPAXVSTNV0KRD1JAT0YZMPJFQNM869B66S72PSF17K4Y8G";
+
+static const char *test_multibase_key =
+  "u7QEJX5oaWV3edV2CeGhkrQPfpaT71ogyVmNk4rZeE8yeRA";
+
+static const char *test_did_document_format_str =
+  "{\"@context\":[\"https://www.w3.org/ns/did/v1\",\
+  \"https://w3id.org/security/suites/ed25519-2020/v1\"],\
+  \"id\":\"%s\",\
+  \"verificationMethod\":[{\
+  \"id\":\"%s#key-1\",\
+  \"type\":\"Ed25519VerificationKey2020\",\
+  \"controller\":\"%s\",\
+  \"publicKeyMultibase\":\"%s\"}],\
+  \"authentication\":[\"#key-1\"],\
+  \"assertionMethod\":[\"#key-1\"]}";
+
+static struct GNUNET_IDENTITY_PrivateKey test_skey;
+static struct GNUNET_IDENTITY_PublicKey test_pkey;
+static struct json_t *test_did_document;
+static char *test_did_document_str;
+
+void
+test_GNUNET_DID_pkey_to_did ()
+{
+  char *str_did;
+  str_did = DID_pkey_to_did (&test_pkey);
+  GNUNET_assert (strcmp ((char *) test_did, str_did) == 0);
+}
+
+void
+test_GNUNET_DID_did_to_pkey ()
+{
+  struct GNUNET_IDENTITY_PublicKey pkey;
+  DID_did_to_pkey ((char *) test_did, &pkey);
+
+  GNUNET_assert (test_pkey.type = pkey.type);
+  GNUNET_assert (strcmp (pkey.eddsa_key.q_y,
+                         test_pkey.eddsa_key.q_y) == 0);
+}
+
+// void
+// test_GNUNET_DID_key_covert_multibase_base64_to_gnunet ();
+
+void
+test_GNUNET_DID_key_covert_gnunet_to_multibase_base64 ()
+{
+  char *multibase_key;
+  multibase_key = DID_key_covert_gnunet_to_multibase_base64 (&test_pkey);
+
+  GNUNET_assert (strcmp (test_multibase_key, multibase_key) == 0);
+}
+
+void
+test_GNUNET_DID_pkey_to_did_document ()
+{
+  struct json_t *did_document;
+  char *did_document_str = DID_pkey_to_did_document (&test_pkey);
+  did_document = json_loads (did_document_str, JSON_DECODE_ANY, NULL);
+  GNUNET_assert (json_equal (test_did_document, did_document) == 1);
+}
+
+int
+main ()
+{
+  // Setup key
+  test_skey.type = htonl (GNUNET_IDENTITY_TYPE_EDDSA);
+  memcpy (&(test_skey.eddsa_key),
+          test_skey_bytes,
+          sizeof(struct GNUNET_CRYPTO_EddsaPrivateKey));
+  GNUNET_IDENTITY_key_get_public (&test_skey, &test_pkey);
+
+  // Setup did document
+  GNUNET_asprintf (&test_did_document_str,
+                   test_did_document_format_str,
+                   test_did,
+                   test_did,
+                   test_did,
+                   test_multibase_key);
+  test_did_document = json_loads (test_did_document_str, JSON_DECODE_ANY, 
NULL);
+
+  // Do tests
+  test_GNUNET_DID_pkey_to_did ();
+  test_GNUNET_DID_did_to_pkey ();
+  test_GNUNET_DID_pkey_to_did_document ();
+  test_GNUNET_DID_key_covert_gnunet_to_multibase_base64 ();
+  return 0;
+}
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]