DID Store provides a series of load API for reading objects, which can support reading Root Identity, DID Document, and Verifiable Credential within.
However, for security reasons, the private key stored in DID Store cannot be read directly but can only be used transparently through the signature or encrypted API.
id is the identifier string of Root Identity. If the DID Store has only one Root Identity, the api can be used without ID identification, as the example above (or the acquisition will fail).
The result is Root Identity object. Attention: The Root Identity object needs to be destroyed with RootIdentity_Destroy after it's used.
DIDDocument *DIDStore_LoadDID(DIDStore *store, DID *did);
If the DID content doesn't exist or the DID Document is saved in the wrong format, the acquisition fails. Note: There are many ways to get DID object, and the example is just one of them. Users can use API according to their own needs. See DID/Create DID and DID Document chapter for details.
The result is DID Document object (also the DID content saved by DID Store). Attention: The Root Identity object needs to be destroyed with RootIdentity_Destroy after it's used.
Credential *DIDStore_LoadCredential( DIDStore *store, DID *did, DIDURL *credid);
did is the DID belonging to Credential; credid is the unique identifier of Credential. If the credential does not exist or the format is incorrect, the acquisition fails. Note: There are many ways to get DIDURL object, the example is just one of them, and users can use API according to their own needs. See DID/Create DID and DID Document section for details.
The result is Credential object. Attention: The Credential object needs to be destroyed with Credential_Destroy after it is used.
Save DID Information in DID Store
DID Store provides a series of APIs for saving DID information, mainly including DID Document, Verifiable credential, and Private key.
Among them, saving the private key is mainly used to add the public key in the key pair to the Document when DID Document adds the key, and the private key is encrypted and saved to the DID Store, which is used for authorization and entrustment of DID.
storepass is used to encrypt and save the private key in DID Store; privateKeyis an 82-bit extended private key; size is the length of the private key.
Enumerate Objects in DID Store
DID Store is a background store, and users need to know all DID information saved winth it to get it by enumerating. DID Store provides examples of Root Identity, DID, and Verifiable Credential.
For security reasons, the private key cannot be enumerated.
Example
intget_rootidentity(RootIdentity *rootidentity,void*context){int*count = (int*)context;if (!rootidentity)return0; (*count)++;return0;}intget_did(DID *did,void*context){ DID *d = (DID*)context;if (!did)return0; (*count)++;return0;}constchar*rootPath ="root/store";DIDStore *store =DIDStore_Open(rootPath);... ... ... ...//list RootIdentitiesint count =0;if (DIDStore_ListRootIdentities(store, get_rootidentity, (void*)&count) <0)//error operationif (count >0) printf("there are %d root identities in the DID store.\n", count);elseprintf("there are no root identity in the DID store.\n");... ... ... ... //list DIDscount =0;if (DIDStore_ListDIDs(store,0, get_did, (void*)&count) <0)//error operationif (count >0)printf("there are %d dids in the DID store.\n", count);... ... ... ...DIDStore_Close(store);
Enumerate DID saved in DID store and pass DID to the user through callback. The filer is a DID filter, which is used to indicate the conditions for selecting DID.
typedefintDIDStore_CredentialsCallback(DIDURL *id,void*context);intDIDStore_ListCredentials( DIDStore *store, DID *did, DIDStore_CredentialsCallback *callback,void*context);
Enumerate all credentials of the specified DID and pass the credential ID Enumerate DID saved in DID store, then pass credential ID to the user through callback.
Select Objects in DID Store
The List function can list all objects of the same type in DID Store, and the select function can list DID and Verifiable Credential objects that meet the specified conditions.
This method selects the eligible Credential method according to type and credid, and then returns the eligible Credential Id and puts it in the creds array.
creds is an array provided by the user to store the Id of eligible Credential, and size is the array size. There must be one value exists in type and credid, otherwise an error will be reported.
Delete Objects in DID Store
DID Store provides a method to save DID objects as well as a method to delete them, which need to delete Root Identity, DID, Verifiable Credential, and Private key consecutively.
This method is used to delete the Root Identity identified as id. If there is no such Root Identity, or the Root Identity is the only object in DID store, then it cannot be deleted; return to false.
boolDIDStore_DeleteDID(DIDStore *store, DID *did);
This method is used to delete all did-related contents saved in DID Store, such as documents, credentials, and private keys. If there is no DID information or an error occurs, it will return to false.
boolDIDStore_DeleteCredential(DIDStore *store, DID *did, DIDURL *id);
This method is used to delete Credential. If there is no Credential information or an error occurs, it will return to false.
did is the owner of Credential, and id is Credential identification.
This method provides the private key for deleting keyid. If there is no private key information or an error occurs, it will return to false.
Check whether there are Objects in DID Store
Sometimes users only need to know whether an object is saved in DID store. Therefore, DID store provides a method to check the existence of Root Identity, Mnemonic, DID, Verifiable Credential, and Private key.