issue
In this tutorial, you will learn how to send a VC to a specific 'holder'. The process of sending VC is VC Issue mode.
Complete code example: zkid-sdk-example /src/issue/issue.ts
Tutorial
Initialize @noble cryptographic library and wasm;
Get DID object of holder and attester;
In the above process, the use of the following three APIs is mainly involved:
Get resolver object, using
resolve
method get DID document from DID URL; Theresolver
can be some APIs parameters. For this kind of API, developers should explicitly specifyresolver
in their use, especially if you are developing in our development environment. This is because ourresolver
connects to the production environment by default, and if you don't specify aresolver
, it may occurs the DID Method won't be found problem.
Recover DID object by DID Document. The corresponding method is
fromDidDocument
. The DID document is obtained through the resolver'sresolve
interface.
Recover DID object by DID-keys-file. The corresponding method is
restore
. This method recovers DID object by inputing corresponding DID-keys-file contents and password where the password parameter is the password set when backing up the DID-keys-file;
tips: In addition to recovering the DID using the above methods, we also provide an API to recover the DID via mnemonics:
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: holder/claimer, 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);
Build the
vcBuilder
object. In this step, we build a vcBuilder object from which subsequent VCs can be built. vcBuilder provides several methods. For general purpose VCs, it is usually set to never expire and the issue time is set to the current time;
Build the
VC
object. In this step, you will use thebuild
API in vcBuilder to build the VC. The two parameters of this API are described below:issuer: issuer's DID object;
isPublic: true/false, when this parameter is false, the generated VC is private VC. If it is true, then public VC is generated.
Constructing encrypted messages using VC as message data. We will use the
encryptMessage
API to generate encrypted messages with the API parameters:type: Message type, corresponding to the VC's issue mode, is "Send_issuedVC";
data: Message data, here is VC;
sender: Message sender's DID object, here is VC issuer;
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, by following the 9 steps above, you will learn how to utilize the Issue mode of VC to issue a VC directly to the target user.
Last updated