Using The Provider

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 yarn
yarn add @zcloak/login-providers @zcloak/login-verify @zcloak/did-resolver

# use npm
npm install @zcloak/login-providers @zcloak/login-verify @zcloak/did-resolver

A Simple Example Of How To Use The Provider:

// import ZkidWalletProvider
import { ZkidWalletProvider } from "@zcloak/login-providers";
import { ArweaveDidResolver } from "@zcloak/did-resolver";

import {
  } from '@zcloak/login-verify';

// init zkid wallet provider, make sure zkid wallet is install
const provider = new ZkidWalletProvider();

// init zkid did resolver
const resolver = new ArweaveDidResolver({ server: "" });

async function main() {
  // API for checking authorization status: can be used to check whether the User has permitted the authorization to this website. 
  const isAuth = await provider.isAuth();
  // API for request authorization: If the authorization has not been permitted yet, request authorization from the User
  await provider.requestAuth();
  // API for getting user DID: Get current DID of User from the zkID Wallet
  const currentDid = await provider.getCurrentDid();

  // Create a message to sign    
  const message = 'Test_String';
  const signature = await provider.sign(message);
  const verifyDidLoginResult = await verifyDidLogin(message, signature, resolver);
  const challenge = 'Some_Random_Challenge';
  // API for obtaining a credential Digest Disclosure from the User     
  const credentialDigest = await provider.requestCredentialDigest(challenge);
  const credentialDigestResult = await verifyCredentialDigest(credentialDigest, challenge, currentDid.didUri, resolver);
  // API for getting a credential Selective Disclosure from the User (e.g. disclose `name` and `age`)    
  const credential = await provider.requestCredentialContent(challenge, ['name', 'age']);
  const credentialContentResult = await verifyCredentialContent(credential, challenge, currentDid.didUri, resolver);

Last updated