You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A DIDDoc is a set of data describing the DID subject, including mechanisms, such as cryptographic public keys, that the DID subject or a DID delegate can use to authenticate itself and prove its association with the DID. A DID document might have one or more different representations
// Create a diddoc handle.// Params : None// Return [DIDDoc *] : a diddoc handle if successful, or NULL if failed.DIDDoc*iotex_diddoc_new(void)
// Destroy a diddoc.// Params [DIDDoc *] : a diddoc handle from ‘iotex_diddoc_new’.// Return : None.voidiotex_diddoc_destroy(DIDDoc*doc)
// Create a VerificationMethod handle.// Params [DIDDoc *] : a diddoc handle from ‘iotex_diddoc_new’.// Params [enum VerificationMethod_Purpose] : Purpose of VerificationMethod. See Definition.// Params [enum VerificationMethod_Type] : Type of VerificationMethod. See Definition.// Return [DIDDoc_VerificationMethod*] : a VerificationMethod handle if successful, or NULL if failed.DIDDoc_VerificationMethod*iotex_diddoc_verification_method_new(DIDDoc*diddoc, enumVerificationMethod_Purposepurpose, enumVerificationMethod_Typetype)
// Create a VerificationMethod Map handle.// Params : None// Return [VerificationMethod_Map] : a VerificationMethod Map handle if successful, or NULL if failed.VerificationMethod_Mapiotex_diddoc_verification_method_map_new(void)
// Setting the VerificationMethod_Map value.// Params [VerificationMethod_Map] : a VerificationMethod_Map handle from ‘iotex_diddoc_verification_method_map_new’.// Params [build_type] : Construction Type.// IOTEX_DIDDOC_BUILD_VM_MAP_TYPE_ID// IOTEX_DIDDOC_BUILD_VM_MAP_TYPE_TYPE// IOTEX_DIDDOC_BUILD_VM_MAP_TYPE_CON // IOTEX_DIDDOC_BUILD_VM_MAP_TYPE_JWK // IOTEX_DIDDOC_BUILD_VM_MAP_TYPE_MULTIBASE// IOTEX_DIDDOC_BUILD_VM_MAP_TYPE_BASE58 // Params [void *] : value.// Return [did_status_t] : The result of function execution.did_status_tiotex_diddoc_verification_method_map_set(VerificationMethod_Mapmap, unsigned intbuild_type, void*value)
// Setting the VerificationMethod value.// Params [DIDDoc_VerificationMethod *] : a VerificationMethod handle from ‘iotex_diddoc_verification_method_new’.// Params [enum VerificationMethod_Type] : Type of VerificationMethod. See Definition. // Params [void *] : value.// Return [did_status_t] : The result of function execution.did_status_tiotex_diddoc_verification_method_set(DIDDoc_VerificationMethod*vm, enumVerificationMethod_Typetype, void*value)
// Setting the proerty of diddoc.// Params [DIDDoc *] : a diddoc handle from ‘iotex_diddoc_new’.// Params [build_type] : Construction Type. // IOTEX_DIDDOC_BUILD_PROPERTY_TYPE_CONTEXT// IOTEX_DIDDOC_BUILD_PROPERTY_TYPE_ID// IOTEX_DIDDOC_BUILD_PROPERTY_TYPE_ALSO_KNOWN_AS // IOTEX_DIDDOC_BUILD_PROPERTY_TYPE_CONTROLLER // IOTEX_DIDDOC_BUILD_PROPERTY_TYPE_SERVICE// IOTEX_DIDDOC_BUILD_PROPERTY_TYPE_PROPERTY // Params [name] : name of property, all except IOTEX_DIDDOC_BUILD_PROPERTY_TYPE_PROPERTY will be ignored.// Params [value] : value of property.// Return [did_status_t] : The result of function execution.did_status_tiotex_diddoc_property_set(DIDDoc*diddoc, unsigned intbuild_type, char*name, void*value);
// Create a Service handle.// Params : None. // Return [DIDDoc_Service *] : a DIDDoc_Service handle if successful, or NULL if failed.DIDDoc_Service*iotex_diddoc_service_new(void)
// Setting the DIDDoc_Service value.// Params [DIDDoc_Service *] : a DIDDoc_Service handle from ‘iotex_diddoc_service_new’.// Params [build_type] : Construction Type. // IOTEX_DIDDOC_BUILD_SERVICE_TYPE_ID// IOTEX_DIDDOC_BUILD_SERVICE_TYPE_TYPE// IOTEX_DIDDOC_BUILD_SERVICE_TYPE_ENDPOINT // Params [value] : value of Service.// Return [did_status_t] : The result of function execution.did_status_tiotex_diddoc_service_set(DIDDoc_Service*Service, unsigned intbuild_type, void*value)
// Create a Service Endpoint handle.// Params [enum ServiceEndpoint_type] : Type of ServiceEndpoint. See Definition. // Return [DIDDoc_ServiceEndpoint *] : a ServiceEndpoint handle if successful, or NULL if failed.DIDDoc_ServiceEndpoint*iotex_diddoc_service_endpoint_new(enumServiceEndpoint_typetype)
// Setting the ServiceEndpoint value.// Params [DIDDoc_ServiceEndpoint *] : a ServiceEndpoint handle from ‘iotex_diddoc_service_endpoint_new’.// Params [enum ServiceEndpoint_type] : Type of ServiceEndpoint. See Definition. . // IOTEX_DIDDOC_BUILD_SERVICE_TYPE_ID// IOTEX_DIDDOC_BUILD_SERVICE_TYPE_TYPE// IOTEX_DIDDOC_BUILD_SERVICE_TYPE_ENDPOINT // Params [value] : value of Service.// Return [did_status_t] : The result of function execution.did_status_tiotex_diddoc_service_endpoint_set(DIDDoc_ServiceEndpoint*ServiceEndpoint, enumServiceEndpoint_typetype, void*value)
// Output diddoc.// Params [DIDDoc *] : a diddoc handle from ‘iotex_diddoc_new’.// Params [format] : If true, the output is formatted, if false the output is unformatted.// Return [char *] : a output of the diddoc if successful, or NULL if failed.char*iotex_diddoc_serialize(DIDDoc*diddoc, boolformat)
Example
did_status_tdid_status;
DIDDoc*peerDIDDoc=iotex_diddoc_new();
if (NULL==peerDIDDoc) {
printf("Failed to new a peerDIDDoc\n");
goto exit;
}
did_status=iotex_diddoc_property_set(peerDIDDoc, IOTEX_DIDDOC_BUILD_PROPERTY_TYPE_CONTEXT, NULL, "https://www.w3.org/ns/did/v1");
did_status=iotex_diddoc_property_set(peerDIDDoc, IOTEX_DIDDOC_BUILD_PROPERTY_TYPE_CONTEXT, NULL, "https://w3id.org/security#keyAgreementMethod");
did_status=iotex_diddoc_property_set(peerDIDDoc, IOTEX_DIDDOC_BUILD_PROPERTY_TYPE_ID, NULL, peerSignDID);
if (DID_SUCCESS!=did_status) {
printf("iotex_diddoc_property_set [%d] ret %d\n", IOTEX_DIDDOC_BUILD_PROPERTY_TYPE_ID, did_status);
goto exit;
}
// Make a verification method [type : authentication]DIDDoc_VerificationMethod*vm_authentication=iotex_diddoc_verification_method_new(peerDIDDoc, VM_PURPOSE_AUTHENTICATION, VM_TYPE_DIDURL);
if (NULL==vm_authentication) {
printf("Failed to iotex_diddoc_verification_method_new()\n");
}
did_status=iotex_diddoc_verification_method_set(vm_authentication, VM_TYPE_DIDURL, peerSignKID);
if (DID_SUCCESS!=did_status) {
printf("iotex_diddoc_verification_method_set ret %d\n", did_status);
goto exit;
}
VerificationMethod_Mapvm_map_1=iotex_diddoc_verification_method_map_new();
did_status=iotex_diddoc_verification_method_map_set(vm_map_1, IOTEX_DIDDOC_BUILD_VM_MAP_TYPE_ID, peerSignKID);
did_status=iotex_diddoc_verification_method_map_set(vm_map_1, IOTEX_DIDDOC_BUILD_VM_MAP_TYPE_TYPE, "JsonWebKey2020");
did_status=iotex_diddoc_verification_method_map_set(vm_map_1, IOTEX_DIDDOC_BUILD_VM_MAP_TYPE_CON, peerSignDID);
did_status=iotex_diddoc_verification_method_map_set(vm_map_1, IOTEX_DIDDOC_BUILD_VM_MAP_TYPE_JWK, _did_jwk_json_generate(peerSignJWK));
// Make a verification method [type : key agreement]DIDDoc_VerificationMethod*vm_agreement=iotex_diddoc_verification_method_new(peerDIDDoc, VM_PURPOSE_KEY_AGREEMENT, VM_TYPE_DIDURL);
if (NULL==vm_agreement) {
printf("Failed to iotex_diddoc_verification_method_new()\n");
}
did_status=iotex_diddoc_verification_method_set(vm_agreement, VM_TYPE_DIDURL, peerKAKID);
if (DID_SUCCESS!=did_status) {
printf("iotex_diddoc_verification_method_set ret %d\n", did_status);
goto exit;
}
VerificationMethod_Mapvm_map_2=iotex_diddoc_verification_method_map_new();
did_status=iotex_diddoc_verification_method_map_set(vm_map_2, IOTEX_DIDDOC_BUILD_VM_MAP_TYPE_ID, peerKAKID);
did_status=iotex_diddoc_verification_method_map_set(vm_map_2, IOTEX_DIDDOC_BUILD_VM_MAP_TYPE_TYPE, "JsonWebKey2020");
did_status=iotex_diddoc_verification_method_map_set(vm_map_2, IOTEX_DIDDOC_BUILD_VM_MAP_TYPE_CON, peerSignDID);
did_status=iotex_diddoc_verification_method_map_set(vm_map_2, IOTEX_DIDDOC_BUILD_VM_MAP_TYPE_JWK, _did_jwk_json_generate(peerKAJWK));
DIDDoc_VerificationMethod*vm_vm=iotex_diddoc_verification_method_new(peerDIDDoc, VM_PURPOSE_VERIFICATION_METHOD, VM_TYPE_MAP);
did_status=iotex_diddoc_verification_method_set(vm_vm, VM_TYPE_MAP, vm_map_1);
did_status=iotex_diddoc_verification_method_set(vm_vm, VM_TYPE_MAP, vm_map_2);
char*peerDIDDoc_Serialize=iotex_diddoc_serialize(peerDIDDoc, true);
if (peerDIDDoc_Serialize)
printf("DIDdoc : \n%s\n", peerDIDDoc_Serialize);
iotex_diddoc_destroy(peerDIDDoc);