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.
Installation: yarn add @zcloak/login-providers
Selection:
BaseProvider and Events, BaseProvider accept a request function defined by @zcloak/login-rpc, the events needs to implements by each provider.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.Usage: ZkidWalletProvider Initialization
import { ZkidWalletProvider } from '@zcloak/login-providers'
const provider = new ZkidWalletProvider();
// Check if the extension is installed before usedprovider.isInstalled();
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})
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> {
//......
}
32001, it means that the User rejects this request.Boolean - whether the User request for authorization is successfully allowed.isAuth()
public isAuth(): Promise<boolean> {
//......
}
true, developer can continue to call other APIs. Otherwise, developer must first call wallet_requestAuth() to get permission.