zkID Login Doc
  • Guide
    • Introduction
      • Why zkID-Login
      • DID Account Management
      • VC Management
      • Blockchain Connection
    • Basic Concepts
      • DID
        • DID Protocol Main Architecture
        • ZK DID Method
        • DID-Keys
      • VC
        • What are Verifiable Credentials
        • Key roles of VC
        • Core Data Model
    • Architecture
      • zkID Wallet
      • Provider
    • Usage of VC
      • Digest Disclosure
      • Selective Disclosure
      • All Credential Content Disclosure
  • API Reference
    • Provider API
    • Events
    • Errors
    • Using The Provider
  • SDK
    • Introduction
    • Method
      • verifyDidLogin
      • verifyCredentialDigest
      • verifyCredentialContent
  • Getting Started
    • Preliminary Preparation
    • Use Case
      • Login with DID
      • Login with Digest Disclosure
      • Login with Selective Disclosure
Powered by GitBook
On this page
  • Install packages
  • A Simple Example Of How To Use The Provider:
  1. API Reference

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 {
  verifyCredentialContent,
  verifyCredentialDigest,
  verifyDidLogin>
  } 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: "https://did-service.zkid.app" });

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);
  
}
PreviousErrorsNextSDK

Last updated 2 years ago