aboutsummaryrefslogtreecommitdiff
path: root/src/reclaim/did_core.h
blob: 842424e14338e716f1a9c3df83308043874ad3da (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
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);