diff options
Diffstat (limited to 'src/did/gnunet-did.c')
-rw-r--r-- | src/did/gnunet-did.c | 101 |
1 files changed, 71 insertions, 30 deletions
diff --git a/src/did/gnunet-did.c b/src/did/gnunet-did.c index bf5901a79..e2b32c272 100644 --- a/src/did/gnunet-did.c +++ b/src/did/gnunet-did.c | |||
@@ -18,7 +18,8 @@ | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | // TODO: Public Key in DID Docuement - pkey_multibase_json | 21 | // TODO: Own GNS type |
22 | // TODO: Save delete and move DIDD to root - look for other with same sub | ||
22 | // TODO: uncrustify | 23 | // TODO: uncrustify |
23 | // TODO: Unit Tests | 24 | // TODO: Unit Tests |
24 | 25 | ||
@@ -96,12 +97,6 @@ static struct GNUNET_NAMESTORE_Handle * namestore_handle; | |||
96 | static struct GNUNET_IDENTITY_Handle * identity_handle; | 97 | static struct GNUNET_IDENTITY_Handle * identity_handle; |
97 | const static struct GNUNET_CONFIGURATION_Handle * my_cfg; | 98 | const static struct GNUNET_CONFIGURATION_Handle * my_cfg; |
98 | 99 | ||
99 | // TODO | ||
100 | // eddsa only | ||
101 | // safe delete the didd record - look for other with same sub | ||
102 | // Add a data DID Document type | ||
103 | // Set Record flag when storing did | ||
104 | |||
105 | /** | 100 | /** |
106 | * @brief Disconnect and shutdown | 101 | * @brief Disconnect and shutdown |
107 | * @param cls closure | 102 | * @param cls closure |
@@ -349,48 +344,85 @@ char * | |||
349 | create_did_generate(struct GNUNET_IDENTITY_PublicKey pkey) | 344 | create_did_generate(struct GNUNET_IDENTITY_PublicKey pkey) |
350 | { | 345 | { |
351 | char * pkey_str; // Convert public key to string | 346 | char * pkey_str; // Convert public key to string |
352 | char did_str[71]; // 58 + 12 + 1= 71 | 347 | char did_str[71]; // 58 + 12 + 1 = 71 |
353 | char * didd_str; | 348 | char * didd_str; |
354 | char pkey_multibase_str[60]; // 58 + 1 + 1 = 60 | 349 | char verify_id_str[77]; // did_str len + "#key-1" = 71 + 6 = 77 |
350 | char * pkey_multibase_str; | ||
351 | |||
352 | char * b64; | ||
353 | char pkx[34]; | ||
354 | pkx[0] = 0xed; | ||
355 | pkx[1] = 0x01; | ||
356 | memcpy(pkx+2, &(pkey.eddsa_key), sizeof(pkey.eddsa_key)); | ||
357 | GNUNET_STRINGS_base64_encode(pkx, sizeof(pkx), &b64); | ||
355 | 358 | ||
359 | GNUNET_asprintf(&pkey_multibase_str, "u%s", b64); | ||
360 | |||
361 | json_t * didd; | ||
356 | json_t * did_json; | 362 | json_t * did_json; |
357 | json_t * pkey_multibase_json; | 363 | json_t * pkey_multibase_json; |
364 | json_t * context_json; | ||
358 | json_t * context_1_json; | 365 | json_t * context_1_json; |
359 | json_t * context_2_json; | 366 | json_t * context_2_json; |
360 | json_t * auth_type_json; | 367 | json_t * verify_json; |
361 | json_t * context_json; | 368 | json_t * verify_1_json; |
362 | json_t * auth_json; | 369 | json_t * verify_1_type_json; |
363 | json_t * auth_1_json; | 370 | json_t * verify_1_id_json; |
364 | json_t * didd; | 371 | json_t * verify_relative_ref_json; |
372 | json_t * auth_json; | ||
373 | json_t * assert_json; | ||
365 | 374 | ||
366 | pkey_str = GNUNET_IDENTITY_public_key_to_string(&pkey); // Convert public key to string | 375 | pkey_str = GNUNET_IDENTITY_public_key_to_string(&pkey); // Convert public key to string |
367 | sprintf(did_str, "did:reclaim:%s", pkey_str); // Convert the public key to a DID str | 376 | sprintf(did_str, "did:reclaim:%s", pkey_str); // Convert the public key to a DID str |
368 | sprintf(pkey_multibase_str, "V%s", pkey_str); // Convert the public key to MultiBase data format | 377 | sprintf(verify_id_str, "did:reclaim:%s#key-1", pkey_str); // Convert the public key to a DID str |
369 | 378 | ||
370 | // Create DID Document | 379 | // sprintf(pkey_multibase_str, "V%s", pkey_str); // Convert the public key to MultiBase data format |
380 | |||
381 | // Create Json Strings | ||
371 | did_json = json_string(did_str); | 382 | did_json = json_string(did_str); |
372 | pkey_multibase_json = json_string(pkey_multibase_str); | 383 | pkey_multibase_json = json_string(pkey_multibase_str); |
384 | |||
373 | context_1_json = json_string("https://www.w3.org/ns/did/v1"); | 385 | context_1_json = json_string("https://www.w3.org/ns/did/v1"); |
374 | context_2_json = json_string("https://w3id.org/security/suites/ed25519-2020/v1"); | 386 | context_2_json = json_string("https://w3id.org/security/suites/ed25519-2020/v1"); |
375 | auth_type_json = json_string("Ed25519VerificationKey2020"); | 387 | verify_1_id_json = json_string(verify_id_str); |
388 | verify_1_type_json = json_string("Ed25519VerificationKey2020"); | ||
389 | |||
390 | // Add a relative DID URL to reference a verifiation method | ||
391 | // https://www.w3.org/TR/did-core/#relative-did-urls` | ||
392 | verify_relative_ref_json = json_string("#key-1"); | ||
376 | 393 | ||
394 | // Create DID Document | ||
395 | didd = json_object(); | ||
396 | |||
397 | // Add context | ||
377 | context_json = json_array(); | 398 | context_json = json_array(); |
378 | json_array_append(context_json, context_1_json); | 399 | json_array_append(context_json, context_1_json); |
379 | json_array_append(context_json, context_2_json); | 400 | json_array_append(context_json, context_2_json); |
380 | |||
381 | auth_json = json_array(); | ||
382 | auth_1_json = json_object(); | ||
383 | json_object_set(auth_1_json, "id", did_json); | ||
384 | json_object_set(auth_1_json, "type", auth_type_json); | ||
385 | json_object_set(auth_1_json, "controller", did_json); | ||
386 | json_object_set(auth_1_json, "publicKeyMultiBase", pkey_multibase_json); | ||
387 | json_array_append(auth_json, auth_1_json); | ||
388 | |||
389 | didd = json_object(); | ||
390 | json_object_set(didd, "@context", context_json); | 401 | json_object_set(didd, "@context", context_json); |
402 | |||
403 | // Add id | ||
391 | json_object_set(didd, "id", did_json); | 404 | json_object_set(didd, "id", did_json); |
405 | |||
406 | // Add verification method | ||
407 | verify_json = json_array(); | ||
408 | verify_1_json = json_object(); | ||
409 | json_object_set(verify_1_json, "id", verify_1_id_json); | ||
410 | json_object_set(verify_1_json, "type", verify_1_type_json); | ||
411 | json_object_set(verify_1_json, "controller", did_json); | ||
412 | json_object_set(verify_1_json, "publicKeyMultiBase", pkey_multibase_json); | ||
413 | json_array_append(verify_json, verify_1_json); | ||
414 | json_object_set(didd, "verificationMethod", verify_json); | ||
415 | |||
416 | // Add authentication method | ||
417 | auth_json = json_array(); | ||
418 | json_array_append(auth_json, verify_relative_ref_json); | ||
392 | json_object_set(didd, "authentication", auth_json); | 419 | json_object_set(didd, "authentication", auth_json); |
393 | 420 | ||
421 | // Add assertion method to issue a Verifiable Credential | ||
422 | assert_json = json_array(); | ||
423 | json_array_append(assert_json, verify_relative_ref_json); | ||
424 | json_object_set(didd, "assertionMethod", assert_json); | ||
425 | |||
394 | // Encode DID Document as JSON string | 426 | // Encode DID Document as JSON string |
395 | didd_str = json_dumps(didd, JSON_INDENT(2)); | 427 | didd_str = json_dumps(didd, JSON_INDENT(2)); |
396 | if(didd_str == NULL) | 428 | if(didd_str == NULL) |
@@ -400,15 +432,24 @@ create_did_generate(struct GNUNET_IDENTITY_PublicKey pkey) | |||
400 | ret = 1; | 432 | ret = 1; |
401 | return NULL; | 433 | return NULL; |
402 | } | 434 | } |
435 | |||
436 | // TODO: MORE FREEEEEEEE | ||
437 | free(pkey_multibase_str); | ||
438 | free(b64); | ||
403 | 439 | ||
440 | free(didd); | ||
404 | free(did_json); | 441 | free(did_json); |
405 | free(pkey_multibase_json); | 442 | free(pkey_multibase_json); |
443 | free(context_json); | ||
406 | free(context_1_json); | 444 | free(context_1_json); |
407 | free(context_2_json); | 445 | free(context_2_json); |
408 | free(auth_type_json); | 446 | free(verify_json); |
447 | free(verify_1_json); | ||
448 | free(verify_1_type_json); | ||
449 | free(verify_1_id_json); | ||
409 | free(auth_json); | 450 | free(auth_json); |
410 | free(auth_1_json); | 451 | free(assert_json); |
411 | free(didd); | 452 | free(verify_relative_ref_json); |
412 | 453 | ||
413 | return didd_str; | 454 | return didd_str; |
414 | } | 455 | } |