claim
In this tutorial, we will simulate a Claimer to make a VC issuance request to a specified Attester with the help of SDK.
Complete code example: zkid-sdk-example /src/claim-attest/claim.ts
Tutorial
Initialize @noble cryptographic library and wasm;
Get the DID objects of claimer and attester;
The above sample code presents the ways to recover the DID object are: through the mnemonic recovery and through the DID document recovery. The main APIs involved are:
fromMnemonic
, which recovers the DID object by means of a mnemonic, takes as mandatory arguments a keyring and a mnemonic in the form of a string, the keyring being the structure that manages the keypair;
fromDidDocument
, which recovers the DID object by means of a DID document, takes didDocuemnt as mandatory arguments. DID documents are obtained through the resolver'sresolve
API;
Get ctype object from ctype hash;
In this step, ctypeHash will be used as the query parameter of the HTTP GET request to get the ctype object.
Build the
Raw
object. In this step, we build a Raw object which is used for the subsequent construction of the RawCredential. The following explains each property of the Raw object:contents: The body of the credential;
owner: claimer/holder, credential receiver;
ctype: The ctype object used for this credential;
hashType: Encryption algorithm type, here choose Keccak256 (we also support Blake2, Blake3, RescuePrimeOptimized and other encryption algorithms. Note: Considering that Keccak256 has the highest hash efficiency on chain, it is recommended to use Keccak256 as the hash when building Raw if your vc usage scenario does not include zk computation, otherwise use RescuePrimeOptimized hash).
Build the
RawCredential
object. In this step, we calltoRawCredential
API to generate RawCredential object based on the Raw object generated in the previous step. The encryption algorithm used in this step is Keccak256 by default (meanwhile, we also support other encryption algorithms, which are the same as the ones available for building Raw);
Construct an encrypted message of type Request_Attestation using RawCredential as the message data. We will generate the encrypted message using the
encryptMessage
API with the following parameters:type: Message type, In VC's request mode, the message type for a claim scenario is "Request_Attestation";
data: Message data, here is RawCredential;
sender: Message sender's DID object, here is claimer;
receiverUrl: Message receiver's keyAgreement DID URL;
reply: Prefixed message id, this parameter is only used for responding to message scenarios;
resolver: DID resolver.
Send the encrypted message to the server. This process initiates an HTTP POST request.
Well, with the above introduction, you will learn how to use our SDK as a claimer to make a request to one of the attester you specified. So far, this is only half of the VC request mode, so let's focus on the attester's perspective and explore how to respond to a request and send a VC.
Last updated