@zbyteio/zbyte-wallet-sdk-core
TypeScript icon, indicating that this package has built-in type declarations

1.1.5 • Public • Published

zbyte Wallet core SDK

SDK contains all the core functionality related to zbyte wallet, and can be supported on browser(client side code).

Installation

    npm install @zbyteio/zbyte-wallet-sdk-core

Documentation

The zbyte core wallet manages user account creation and interacts with the DPLAT token. Key features include:

  • Viewing the current DPLAT balance and transferring it to another account.
  • Support for Polygon and Avalanche C-Chain blockchains.
  • Management of key pairs through third-party libraries referred to as External Key Providers (EKP).
  • Current supported EKPs include Web3auth and Metamask.

Since the DPLAT token is not a Layer 1 (L1) token, zbyte wallet defines some mandatory interfaces:

Interfaces

IWalletProvider

interface IWalletProvider {
    /**
     * @description Connect to the wallet provider.
     */
    connect(): Promise<any>;

    /**
     * @description Check if the wallet provider is connected.
     */
    isConnected(): boolean;

    /**
     * @description Fetch the wallet provider which internally sets the provider.
     * @param networkConfig Blockchain Network parameters.
     */
    getKeyProvider(networkConfig: NetworkConfig): Promise<IKeyProvider>;
}

IKeyProvider

interface IWalletProvider {
    /**
     * @description Connect to the wallet provider.
     */
    connect(): Promise<any>;

    /**
     * @description Check if the wallet provider is connected.
     */
    isConnected(): boolean;

    /**
     * @description Fetch the wallet provider which internally sets the provider.
     * @param networkConfig Blockchain Network parameters.
     */
    getKeyProvider(networkConfig: NetworkConfig): Promise<IKeyProvider>;
}

Key APIs

  • isConnected()
    • Checks whether the wallet is connected to an underlying key provider like Web3auth or Metamask.
  • connect()
    • Connects to an underlying key provider
  • signTypedData(txnMessage: string, chainId: number)
    • Signs an EIP-712 transaction.
    • Inputs:
      • txnMessage: Serialized EIP-712 message.
      • chainId: Blockchain ID that requires the signature.
  • getAddress()
    • Returns the blockchain address for the user.
  • getTokenBalance(address: string)
    • Provides the zbyte token balance for the given user's address.
    • Input:
      • address: User's blockchain address.

Usage

Below is an example of how to use the wallet SDK:

const web3Auth = new Web3AuthProvider();
const metamask = new MetaMaskProvider();
const walletProvider: IWalletProvider = web3Auth || metamask;

const wallet = new WalletCore(walletProvider, getBlockchainNetwork(CHAIN_ID_MATIC_TESTNET));

// For using Web3auth, the default and preferred provider,
// an extra authentication function is required
wallet.injectAuthVerifier({
    clientId: string;
    domain: string;
    typeOfLogin?: LOGIN_TYPE;
    verifier: string;
    accessToken: string;
    tokenExpiry?: number;
    typeOfToken?: string;
});

if (!wallet.isConnected()) {
    console.log(await wallet.connect()
    .then((result) => {
        console.log("initialized");
        return result;
    })
    .catch(e => console.error(e)));
}

const userAddress = await wallet.getAddress();
const dplatBalance = await wallet.getTokenBalance(userAddress);

For further details and advanced usage, please refer to the official documentation.

Readme

Keywords

Package Sidebar

Install

npm i @zbyteio/zbyte-wallet-sdk-core

Weekly Downloads

9

Version

1.1.5

License

ISC

Unpacked Size

15.2 MB

Total Files

33

Last publish

Collaborators

  • admin_zbyte
  • ckshitij