GNUnet  0.18.1
did_core.h File Reference

Core functionality for GNUNET Decentralized Identifier. More...

#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"
Include dependency graph for did_core.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define DID_DOCUMENT_LABEL   "didd"
 
#define DID_DOCUMENT_DEFAULT_EXPIRATION_TIME   "365d"
 

Typedefs

typedef void DID_resolve_callback(enum GNUNET_GenericReturnValue status, char *did_document, void *cls)
 Signature of a callback function that is called after a did has been resolved. More...
 
typedef void DID_action_callback(enum GNUNET_GenericReturnValue status, void *cls)
 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. More...
 

Functions

enum GNUNET_GenericReturnValue DID_resolve (const char *did, struct GNUNET_GNS_Handle *gns_handle, DID_resolve_callback *cont, void *cls)
 Resolve a DID. More...
 
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)
 Removes the DID Document from namestore. More...
 
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)
 Creates a DID and saves DID Document in Namestore. More...
 
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)
 Replace the DID Document of a DID. More...
 

Detailed Description

Core functionality for GNUNET Decentralized Identifier.

Author
Tristan Schwieren

Definition in file did_core.h.

Macro Definition Documentation

◆ DID_DOCUMENT_LABEL

#define DID_DOCUMENT_LABEL   "didd"

Definition at line 37 of file did_core.h.

◆ DID_DOCUMENT_DEFAULT_EXPIRATION_TIME

#define DID_DOCUMENT_DEFAULT_EXPIRATION_TIME   "365d"

Definition at line 38 of file did_core.h.

Typedef Documentation

◆ DID_resolve_callback

typedef void DID_resolve_callback(enum GNUNET_GenericReturnValue status, char *did_document, void *cls)

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.

Parameters
statusEquals GNUNET_OK if DID Docuemnt has been resolved
did_documentresolved DID Document
clsprevisouly given closure

Definition at line 50 of file did_core.h.

◆ DID_action_callback

typedef void DID_action_callback(enum GNUNET_GenericReturnValue status, void *cls)

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.

Parameters
statusstatus of the perfermormed action.
clsprevisouly given closure

Definition at line 61 of file did_core.h.

Function Documentation

◆ DID_resolve()

enum GNUNET_GenericReturnValue DID_resolve ( const char *  did,
struct GNUNET_GNS_Handle gns_handle,
DID_resolve_callback cont,
void *  cls 
)

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.

Parameters
didDID that is resolved
gns_handlepointer to gns handle.
contcallback function
clsclosure

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.

Parameters
didDID that is resolve

Definition at line 58 of file did_core.c.

91 {
93 
94  // did, gns_handle and cont must me set
95  if ((did == NULL) || (gns_handle == NULL) || (cont == NULL))
96  return GNUNET_NO;
97 
98  if (GNUNET_OK != DID_did_to_pkey (did, &pkey))
99  return GNUNET_NO;
100 
101  // Create closure for lookup callback
102  struct DID_resolve_return *cls_gns_lookup_cb
103  = malloc (sizeof(struct DID_resolve_return));
104  cls_gns_lookup_cb->cb = cont;
105  cls_gns_lookup_cb->cls = cls;
106 
109  &pkey,
113  cls_gns_lookup_cb);
114 
115  return GNUNET_OK;
116 }
#define GNUNET_GNSRECORD_TYPE_DID_DOCUMENT
Record type to store DID Documents.
static void DID_resolve_gns_lookup_cb(void *cls, uint32_t rd_count, const struct GNUNET_GNSRECORD_Data *rd)
GNS lookup callback.
Definition: did_core.c:58
#define DID_DOCUMENT_LABEL
Definition: did_core.h:37
enum GNUNET_GenericReturnValue DID_did_to_pkey(const char *did, struct GNUNET_IDENTITY_PublicKey *pkey)
Return the public key of a DID.
Definition: did_helper.c:79
static struct GNUNET_GNS_Handle * gns_handle
Handle to the GNS service.
uint32_t did
This has a different ID for each parameter, see PRISM_DID_* constants.
static char * pkey
Public key of the zone to look in, in ASCII.
struct GNUNET_GNS_LookupRequest * GNUNET_GNS_lookup(struct GNUNET_GNS_Handle *handle, const char *name, const struct GNUNET_IDENTITY_PublicKey *zone, uint32_t type, enum GNUNET_GNS_LocalOptions options, GNUNET_GNS_LookupResultProcessor proc, void *proc_cls)
Perform an asynchronous lookup operation on the GNS.
Definition: gns_api.c:422
@ GNUNET_GNS_LO_DEFAULT
Defaults, look in cache, then in DHT.
@ GNUNET_OK
@ GNUNET_NO
Definition: gnunet_common.h:99
DID_resolve_callback * cb
Definition: did_core.c:34
An identity key as per LSD0001.

References DID_resolve_return::cb, DID_resolve_return::cls, data, GNUNET_GNSRECORD_TYPE_DID_DOCUMENT, GNUNET_NO, GNUNET_OK, rd, and rd_count.

Referenced by resolve_did().

Here is the caller graph for this function:

◆ DID_remove()

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 
)

Removes the DID Document from namestore.

Ego is not removed. Calls the callback function with status and the given closure.

Parameters
egoego which controlls the DID
cfg_handlepointer to configuration handle
namestore_handlepointer to namestore handle
contcallback function
clsclosure

◆ DID_create()

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 
)

Creates a DID and saves DID Document in Namestore.

Parameters
egoego for which the DID should be created.
did_documentdid_document that should be saved in namestore. If did_document==NULL -> Default DID document is created.
expire_time
namestore_handle
contcallback function
clsclosure
egoego for which the DID should be created.
did_documentdid_document that should be saved in namestore. If did_document==NULL -> Default DID document is created.
namestore_handle
contcallback function
clsclosure

Definition at line 151 of file did_core.c.

226 {
228 
229  // Ego, namestore_handle and cont must be set
230  if ((ego == NULL) || (namestore_handle == NULL) || (cont == NULL))
231  return GNUNET_NO;
232 
233  // Check if ego has EdDSA key
235  &pkey);
236  if (ntohl (pkey.type) != GNUNET_GNSRECORD_TYPE_EDKEY)
237  {
238  printf ("The EGO has to have an EdDSA key pair\n");
239  return GNUNET_NO;
240  }
241 
242  struct DID_action_return *ret
243  = malloc (sizeof(struct DID_action_return));
244  ret->cb = cont;
245  ret->cls = cls;
246 
247  struct DID_create_namestore_lookup_closure *cls_name_store_lookup_cb
248  = malloc (sizeof(struct DID_create_namestore_lookup_closure));
249  cls_name_store_lookup_cb->did_document = did_document;
250  cls_name_store_lookup_cb->expire_time = (*expire_time);
251  cls_name_store_lookup_cb->namestore_handle = namestore_handle;
252  cls_name_store_lookup_cb->ret = ret;
253 
254  // Check if ego already has a DID Document
258  NULL,
259  NULL,
261  (void *) cls_name_store_lookup_cb);
262 
263  return GNUNET_OK;
264 }
#define GNUNET_GNSRECORD_TYPE_EDKEY
Record type for EDKEY zone delegations.
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)
Definition: did_core.c:151
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
static struct GNUNET_NAMESTORE_Handle * namestore_handle
Definition: gnunet-did.c:111
const struct GNUNET_IDENTITY_PrivateKey * GNUNET_IDENTITY_ego_get_private_key(const struct GNUNET_IDENTITY_Ego *ego)
Obtain the ECC key associated with a ego.
Definition: identity_api.c:560
void GNUNET_IDENTITY_ego_get_public_key(struct GNUNET_IDENTITY_Ego *ego, struct GNUNET_IDENTITY_PublicKey *pk)
Get the identifier (public key) of an ego.
Definition: identity_api.c:573
struct GNUNET_NAMESTORE_QueueEntry * GNUNET_NAMESTORE_records_lookup(struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_IDENTITY_PrivateKey *pkey, const char *label, GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls, GNUNET_NAMESTORE_RecordMonitor rm, void *rm_cls)
Lookup an item in the namestore.
struct GNUNET_NAMESTORE_Handle * namestore_handle
Definition: did_core.c:146
struct GNUNET_TIME_Relative expire_time
Definition: did_core.c:145
struct DID_action_return * ret
Definition: did_core.c:147
Handle for an ego.
Definition: identity.h:37

References DID_action_return::cb, DID_action_return::cls, GNUNET_GNSRECORD_Data::data, GNUNET_GNSRECORD_Data::data_size, DID_create_did_store_cb(), DID_create_namestore_lookup_closure::did_document, DID_DOCUMENT_LABEL, DID_pkey_to_did_document(), GNUNET_GNSRECORD_Data::expiration_time, DID_create_namestore_lookup_closure::expire_time, GNUNET_GNSRECORD_Data::flags, GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION, GNUNET_GNSRECORD_typename_to_number(), GNUNET_IDENTITY_key_get_public(), GNUNET_NAMESTORE_records_store(), GNUNET_NO, namestore_handle, pkey, rd_count, GNUNET_GNSRECORD_Data::record_type, GNUNET_TIME_Relative::rel_value_us, and zone.

Referenced by create_did_ego_lockup_cb().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DID_replace()

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 
)

Replace the DID Document of a DID.

Parameters
egoego for which the DID Document should be replaced
did_documentnew DID Document
cfg_handlepointer to configuration handle
identity_handlepointer to configuration handle
namestore_handlepointer to namestore handle
contcallback function
clsclosure