@zbyte-io/zbyte-wallet-sdk-core
v1.1.2
Published
Core functionality of zbyte wallet, currently is getting consumed by zbyte-wallet-ui-sdk
Downloads
3
Readme
zbyte Wallet core SDK
SDK contains all the core functionality related to zbyte wallet, and can be supported on browser(client side code).
Installation
- To install the lib use npm below npm command
npm install @zbyteio/zbyte-wallet-sdk-core
Documentation
- zbyte core wallet manages the user account creation and worked with DPLAT token.
- User can see the current DPLAT balance and transfer it to another account.
- Supported blockchain's are polygon and avalanche c-chain.
- All the key-pairs are managed by the other third-party libraries which we termed as external key provider(EKP).
- Currently supported external key provider(EKP) are Web3auth and Metamask.
- Since DPLAT Token is not a L1 token, zbyte wallet defined some mandatory interfaces which are mentioned below:
interface IWalletProvider { /** * @description Use to connect the wallet provider. */ connect(): Promise<any>; /** * @description Use to checked whether wallet provider connected or not. */ isConnected(): boolean; /** * @description fetch the wallet provider which internally set the provider * @param networkConfig Blockchain Network parameters */ getKeyProvider(networkConfig: NetworkConfig): Promise<IKeyProvider>; } interface IKeyProvider { /** * @description Name of the key provider */ readonly serviceProviderName: string; /** * @description Add Network to the given key provider * @param networkConfig Network Information of the blockchain */ addChain(networkConfig: NetworkConfig): Promise<void>; /** * @description Switch default network to the given key provider, * switchChain only supported on the added chain. * @param chainId chainId in hex string format e.g 0x89(137) */ switchChain(chainId: string): Promise<void>; getProvider(): any; }
- Then below are some important apis to interact with wallet:
- IsConnected()
- Check whether wallet is connected to underneath key provider like web3auth or metamask.
- Connect()
- Connect to underneath key provider.
- SignTypedData(txnMessage: string, chainId: number)
- Sign the EIP-712 transaction.
- Inputs:
- txnMessage: Serialized EIP-712 message
- chainId: blockchain id which need the signature
- BatchSignTypedData(txnBatch: UnsignedBatchTx): Promise<OperationSign[]>;
- Its used when we need multiple transaction to be signed.
- GetAddress()
- Return the blockchain address for the given user.
- GetTokenBalance(address: string)
- Provide the zbyte token present in the given user's address.
- Input:
- address: User's blockchain address
- IsConnected()
Usage
- Please refer the below code for consuming 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 which is the default and preferred provider // requires extra authentication function 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);