npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@metis.io/middleware-client

v1.2.3

Published

## Change log

Downloads

542

Readme

Nuvo SDK

Change log

  • v1.2.3
    • support signTypedData
  • v1.2.0
    • support ethers6
  • v1.1.41
    • support bitget wallet

SDK install

npm install @metis.io/middleware-client

To enable a user of a website/app to log into Nuvo and access its functionalities such as checking balance and sending transaction, follows these high level steps:

  1. Acquire access token using Oauth2 client
  2. Use the acquired access token to initialize a PolisProvider or PolisClient Object
  3. Use the methods provided by PolisProvider or PolisClient to execute user's Nuvo account's functionalities.

First we use this code example to demostrate how to initialize an Oauth2 client and acquire an access token from a user's account:

Oauth2 client

import & create

import { Oauth2Client } from '@metis.io/middleware-client'

const oauth2Client = new Oauth2Client()

start oauth

/**
 * switchAccount = true:  Does not automatically log in,default:false
 * newWindow: default false
 */

oauth2Client.startOauth2(`APPID`, `RETURN URL`, `newWindow`,`switchAccount`); 

The APPID and RETURN URL can get from Polis Developer User page

request access token & refresh token on RETURN URL page in backend

get(`https://polis.metis.io/api/v1/oauth2/access_token?app_id=${this.appid}&app_key=${this.appsecret}&code=${this.code}`)

// if success
res => {
    if (res.status == 200 && res.data && res.data.code == 200) {
        // res.data.data.access_token
        // res.data.data.refresh_token
        // res.data.data.expires_in
    }
}      

refresh token

const oauth2User = await oauth2Client.refreshTokenAsync(`APPID`, `RefreshToken`)

get user info

const userInfo = await oauth2Client.getUserInfoAsync(`AccessToken`)

// user info struct 
{
    'display_name': '',
    'username': '',
    'email': '',
    'eth_address': '',
    'last_login_time': timestamp
}

oauth logout

// refreshToken:options When refreshtoken is not empty, refreshtoken will also be deleted and cannot be used.
logout(appId:string, accessToken:string, refreshToken:string="").then(res => {
    //res = {
    //     status: 200 
    //     msg: ""
    // }
})
.catch(res=>{
    // res = {
    //     status: -90016
    //     msg: ""
    // }
})

Once we acquired the access token, we can use either a PolisProvider object that is compatible with ethers provider, or a PolisClient object to access user account's functionalities.

1、Use Ethers BrowserProvider

step 1: IPolisProviderOpts


const opts: IPolisProviderOpts = {
            apiHost: 'https://api.nuvosphere.io/',  // api host
            oauthHost?: "", //oauth login host, options
            token?: {accessToken}, //optional oauth2 access token 
            chainId: 4,
        }
const polisprovider = new PolisProvider(opts)

step 2: Ethers Web3 Provider

const ethersProvider = new ethers.BrowserProvider(polisprovider)

2、 Use Polis Client

step 1


const clientOps:IPolisClientOpts = {
    chainId: CHAIN_ID,
    appId:APP_ID,
    apiHost :apiHost
}
client = new PolisClient(clientOps);
client.web3Provider.getBalance("address")
/**
 * oauthInfo:  get from api: api/v1/oauth2/access_token or token string
 * 
 */
client.connect(oauthInfo);
// 1.1.17 later
await client.connect(oauthInfo);

Polis Client Events

//event of debug
client.on('debug', function (data) {
        console.log('debug data:%s', JSON.stringify(data));
 })
// event of error
client.on('error', function (data) {
    console.log('error:', data instanceof Error)
});
//when metamask wallet
client.on('chainChanged', (chainId) => {
    console.log('polis-client print chainId =>', chainId);
});
client.on('accountsChanged', (account) => {
    console.log('polis-client print account =>', account);
});

step 2: get Web3 Provider

const ethersProvider=client.web3Provider // ethers.BrowserProvider
// v1.2.x
const singer = await ethersProvider.getSinger();
// v1.1.x
// const singer = ethersProvider.getSinger();

singer.signMessage("aa");


const daiAddress = this.contract.address;

const daiAbi = [
    // Some details about the token
    "function name() view returns (string)",
    "function symbol() view returns (string)",

    // Get the account balance
    "function balanceOf(address) view returns (uint)",

    // Send some of your tokens to someone else
    "function transfer(address to, uint amount)",

    // An event triggered whenever anyone transfers to someone else
    "event Transfer(address indexed from, address indexed to, uint amount)"
];

// v1.2.0 later
const daiContract = await client.getContract(daiAddress, daiAbi);
// v1.1.x
// const daiContract =  client.getContract(daiAddress, daiAbi);

await daiContract['name']();