The @zcloak/login-providers module offers generic transport providers that facilitate the transmission of method calls from a Decentralized Application (DApp) to a DID wallet. This module provides an interface for making Remote Procedure Call (RPC) requests and typically implements the RPC methods as defined by the @zcloak/login-rpc module.

Integration steps

  1. Installation: yarn add @zcloak/login-providers

  2. Selection:

    1. All providers has abstract BaseProvider and Events, BaseProvider accept a request function defined by @zcloak/login-rpc, the events needs to implements by each provider.
    2. ZkidWalletProvider for zCloak ID Wallet extension, use it to call methods to extension, and can listen extension events. The request method and the events of ZkidWalletProvider is to get the zkid object injected into the window by the extension.
  3. Usage: ZkidWalletProvider Initialization

    import { ZkidWalletProvider } from '@zcloak/login-providers'
    
    const provider = new ZkidWalletProvider();
    
    // Check if the extension is installed before usedprovider.isInstalled();
    
  4. Events: All providers implement the EventEmitter API. This sections details the events emitted via that API. There are innumerable EventEmitter guides elsewhere, but you can listen for events like this:

    provider.on('did_changed', (did) => {
    // Handle the new did when wallet selected did changed
    // did is an Object of DidInfo
    })
    
    provider.on('lock', (did) => {// Handle the wallet locked})
    
    provider.on('unlock', (did) => {// Handle the wallet unlock})
    

Key Classes and Functions

Login Authorization

A set of important functions to manage the authorization process of granting DApp access to users DID

Key methods include:

requestAuth()

public requestAuth(): Promise<boolean> {
    //......
}

isAuth()

public isAuth(): Promise<boolean> {
    //......
}