This snippet illustrates how to accomplish the APIs above, which includes:
Request authorization from the User
Get the User's DID Information
Request kinds of Credential Disclosure from the User
Ask the User to sign a message and return a signature
....
Install packages
First, you need to install the following packages, you can install them with the command below.
@zcloak/login-providers
@zcloak/login-verify
@zcloak/did-resolver
# use yarnyarnadd@zcloak/login-providers@zcloak/login-verify@zcloak/did-resolver# use npmnpminstall@zcloak/login-providers@zcloak/login-verify@zcloak/did-resolver
A Simple Example Of How To Use The Provider:
// import ZkidWalletProviderimport { ZkidWalletProvider } from"@zcloak/login-providers";import { ArweaveDidResolver } from"@zcloak/did-resolver";import { verifyCredentialContent, verifyCredentialDigest, verifyDidLogin> } from'@zcloak/login-verify';// init zkid wallet provider, make sure zkid wallet is installconstprovider=newZkidWalletProvider();// init zkid did resolverconstresolver=newArweaveDidResolver({ server:"https://did-service.zkid.app" });asyncfunctionmain() {// API for checking authorization status: can be used to check whether the User has permitted the authorization to this website. constisAuth=awaitprovider.isAuth();// API for request authorization: If the authorization has not been permitted yet, request authorization from the Userawaitprovider.requestAuth();// API for getting user DID: Get current DID of User from the zkID WalletconstcurrentDid=awaitprovider.getCurrentDid();// Create a message to sign constmessage='Test_String';constsignature=awaitprovider.sign(message);constverifyDidLoginResult=awaitverifyDidLogin(message, signature, resolver);constchallenge='Some_Random_Challenge';// API for obtaining a credential Digest Disclosure from the User constcredentialDigest=awaitprovider.requestCredentialDigest(challenge);constcredentialDigestResult=awaitverifyCredentialDigest(credentialDigest, challenge,currentDid.didUri, resolver);// API for getting a credential Selective Disclosure from the User (e.g. disclose `name` and `age`) constcredential=awaitprovider.requestCredentialContent(challenge, ['name','age']);constcredentialContentResult=awaitverifyCredentialContent(credential, challenge,currentDid.didUri, resolver);}