gnunet-svn
[Top][All Lists]
Advanced

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

[gnunet] 60/70: - started with DID lib create func


From: gnunet
Subject: [gnunet] 60/70: - started with DID lib create func
Date: Wed, 31 Aug 2022 18:00:54 +0200

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

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

commit d3de2f84f551501f70851c8df4fbd8e5779f248e
Author: Tristan Schwieren <tristan.schwieren@tum.de>
AuthorDate: Wed Jun 29 12:48:26 2022 +0200

    - started with DID lib create func
---
 src/reclaim/did_core.c | 102 ++++++++++++++++++++++++++++++++++++++++++++++++-
 src/reclaim/did_core.h |   4 +-
 2 files changed, 103 insertions(+), 3 deletions(-)

diff --git a/src/reclaim/did_core.c b/src/reclaim/did_core.c
index 5cecc2972..0690a654b 100644
--- a/src/reclaim/did_core.c
+++ b/src/reclaim/did_core.c
@@ -29,13 +29,18 @@
 
 // #define DID_DOCUMENT_LABEL GNUNET_GNS_EMPTY_LABEL_AT
 #define DID_DOCUMENT_LABEL "didd"
+#define DID_DOCUMENT_DEFAULT_EXPIRATION_TIME "1d"
 
 static DID_resolve_callback *resolve_cb;
 static DID_action_callback *action_cb;
 static void *closure;
 
+// ------------------------------------------------ //
+// -------------------- Resolve ------------------- //
+// ------------------------------------------------ //
+
 /**
- * @brief GNS lookup callback. Calls the given callback function 
+ * @brief GNS lookup callback. Calls the given callback function
  * and gives it the DID Document.
  * Fails if there is more than one DID record.
  *
@@ -101,4 +106,97 @@ DID_resolve (const char *did,
                      GNUNET_GNS_LO_DEFAULT, &DID_resolve_gns_lookup_cb, NULL);
 
   return GNUNET_OK;
-}
\ No newline at end of file
+}
+
+// ------------------------------------------------ //
+// -------------------- Create -------------------- //
+// ------------------------------------------------ //
+
+static void
+DID_create_did_store_cb ()
+{
+  return;
+}
+
+/**
+ * @brief Store DID Document in Namestore
+ *
+ * @param didd_str String endoced DID Docuement
+ * @param ego Identity whos DID Document is stored
+ */
+static enum GNUNET_GenericReturnValue
+DID_create_did_store (struct GNUNET_NAMESTORE_Handle *namestore_handle,
+                  char *didd_str, struct GNUNET_IDENTITY_Ego *ego)
+{
+
+  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 ((GNUNET_OK ==
+                                              
DID_DOCUMENT_DEFAULT_EXPIRATION_TIME),
+                                             &expire_time))
+  {
+    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,
+                                    &DID_create_did_store_cb,
+                                    NULL);
+  }
+  else {
+    printf ("Failed to read given expiration time\n");
+    return GNUNET_NO;
+  }
+}
+
+// TODO: Expiration time missing
+
+/**
+ * @brief Creates a DID and saves DID Document in Namestore.
+ *
+ * @param ego ego for which the DID should be created.
+ * If ego==NULL a new ego is created
+ * @param did_document did_document that should be saved in namestore.
+ * If ego==NULL did_document can also be NULL.
+ * Default DID document is created.
+ * @param cfg_handle pointer to configuration handle
+ * @param identity_hanlde pointer to identity handle. Can be NULL if ego!=NULL
+ * @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,
+            struct GNUNET_CONFIGURATION_Handle *cfg_handle,
+            struct GNUNET_IDENTITY_Handle *identity_handle,
+            struct GNUNET_NAMESTORE_Handle *namestore_handle,
+            DID_action_callback *cont,
+            void *cls)
+{
+  struct GNUNET_IDENTITY_PublicKey pkey;
+
+  GNUNET_IDENTITY_ego_get_public_key (ego, &pkey);
+
+  if (did_document != NULL)
+  {
+    printf (
+      "DID Docuement is read from \"did-document\" argument (EXPERIMENTAL)\n");
+  }
+  else
+  {
+    did_document = DID_pkey_to_did_document (&pkey);
+  }
+
+  return GNUNET_OK;
+}
diff --git a/src/reclaim/did_core.h b/src/reclaim/did_core.h
index 21a7cbd89..ba5aaf09c 100644
--- a/src/reclaim/did_core.h
+++ b/src/reclaim/did_core.h
@@ -101,7 +101,8 @@ DID_remove (const struct GNUNET_IDENTITY_Ego *ego,
  * If ego==NULL did_document can also be NULL.
  * Default DID document is created.
  * @param cfg_handle pointer to configuration handle
- * @param identity_hanlde pointer to configuration handle. Can be NULL if 
ego!=NULL
+ * @param identity_handle pointer to identity handle. Can be NULL if ego!=NULL
+ * @param namestore_handle
  * @param cont callback function
  * @param cls closure
  */
@@ -110,6 +111,7 @@ DID_create (const struct GNUNET_IDENTITY_Ego *ego,
             const char *did_document,
             struct GNUNET_CONFIGURATION_Handle *cfg_handle,
             struct GNUNET_IDENTITY_Handle *identity_handle,
+            struct GNUNET_NAMESTORE_Handle *namestore_handle,
             DID_action_callback *cont,
             void *cls);
 

-- 
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]