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

@rsksmart/rlogin

v1.6.0-beta.3

Published

Login tool for RSK

Downloads

1,006

Readme

Integrate rLogin into your app and allow your users to choose their favorite wallets to login. With a single tool you will get connected to their wallet using an API compatible with Metamask, continue developing as you did.

Wallet support:

  • Browser wallets: Metamask, Nifty, Liquality
  • Mobile wallets via Wallet Connect
  • Custodial wallets: Portis, Torus
  • Hardware wallets: Ledger, Trezor, D'Cent

Network support:

  • RSK Mainnet, RSK Testnet
  • Etheruem, Ropsten, Kovan, Rinkeby, Gorely
  • Any RPC-compatible network, like Polygon or Arbitrum

EIP 1193 support

Clients support:

  • ethers, web3.js and others

Any RPC-compatible networks are supported, but our manual QA process is run only for RSK Networks. See the list of networks for which we have enhanced the UI here. Networks that are not in that list are supported too with a generic display.

Getting started

Follow this guide to configure rLogin in minutes

Sample app: rsksmart/rLogin-sample-apps

1. Install rLogin

yarn add @rsksmart/rlogin

Add wallets peer dependencies:

| Wallet provider | Required package | | - | - | | Browser wallets | none | | Wallet Connect | @rsksmart/rlogin-walletconnect2-provider | | Portis | @portis/web3 | | Torus (beta) | @toruslabs/torus-embed | | Trezor | @rsksmart/rlogin-trezor-provider | | Ledger | @rsksmart/rlogin-ledger-provider | | D'Cent | @rsksmart/rlogin-dcent-provider |

yarn add @rsksmart/rlogin-walletconnect2-provider @portis/web3 @toruslabs/torus-embed @rsksmart/rlogin-trezor-provider @rsksmart/rlogin-ledger-provider @rsksmart/rlogin-dcent-provider

2. Create the DOM element

import RLogin, { AddEthereumChainParameter } from '@rsksmart/rlogin'
import { WalletConnect2Provider } from '@rsksmart/rlogin-walletconnect2-provider'
import Portis from '@portis/web3'
import Torus from '@toruslabs/torus-embed'
import { trezorProviderOptions } from '@rsksmart/rlogin-trezor-provider'
import { ledgerProviderOptions } from '@rsksmart/rlogin-ledger-provider'
import { dcentProviderOptions } from '@rsksmart/rlogin-dcent-provider'

const rpcUrls = {
  30: 'https://public-node.rsk.co',
  31: 'https://public-node.testnet.rsk.co',
}

Method 1

const supportedChains = Object.keys(rpcUrls).map(Number)

const infoOptions = {
  30: { addressBaseURL: 'https://explorer.rsk.co/address/' },
  31: { addressBaseURL: 'https://explorer.testnet.rsk.co/address/' }
}

export const rLogin = new RLogin({
  providerOptions: {
    walletconnect: {
      package: WalletConnect2Provider,
      options: {
        projectId: 'PROJECTID',
        chains: ['31'],
        showQrModal: true,
        rpcMap: rpcUrls,
      }
    },
    portis: {
      package: Portis,
      options: {
        id: "a1c8672b-7b1c-476b-b3d0-41c27d575920",
        network: {
          nodeUrl: 'https://public-node.testnet.rsk.co',
          chainId: 31,
        }
      }
    },
    torus: {
        package: Torus,
    },
    'custom-ledger': ledgerProviderOptions,
    'custom-dcent': dcentProviderOptions,
    'custom-trezor': {
      ...trezorProviderOptions,
      options: {
        manifestEmail: '[email protected]',
        manifestAppUrl: 'https://basic-sample.rlogin.identity.rifos.org/',
      }
    }
  },
  rpcUrls,
  supportedChains,
  infoOptions
})

Method 2

Provide an array of supported network parameters to the rLogin constructor within ethereumChains parameter. This will allow you to add selected network to Metamask (if it has not been previously added) and switch to the network if the wallet was initially connected to an unsupported network.

const supportedChains: AddEthereumChainParameter[] = [
  {
    chainId: '0x1e', // hex 30
    chainName: 'RSK Mainnet',
    nativeCurrency: {
      name: 'RSK BTC',
      symbol: 'RBTC',
      decimals: 18
    },
    rpcUrls: ['https://public-node.rsk.co'],
    blockExplorerUrls: ['https://explorer.rsk.co'],
    iconUrls: ['https://developers.rsk.co/assets/img/favicons/android-chrome-192x192.png']
  },
  // previously unknown network
 {
    chainId: '0x4E', // hex 78
    chainName: 'RSK Alphanet',
    nativeCurrency: {
      name: 'Test RSK BTC',
      symbol: 'tRBTC',
      decimals: 18
    },
    rpcUrls: ['https://fullnode-use1-1.alphanet.iovlabs.net'],
    blockExplorerUrls: ['https://explorer.alphanet.rsk.co'],
    iconUrls: ['https://developers.rsk.co/assets/img/favicons/android-chrome-192x192.png']
  }
];

export const rLogin = new RLogin({
  providerOptions: {
    walletconnect: {
      package: WalletConnect2Provider,
      options: {
        projectId: 'PROJECTID',
        chains: supportedChains.map(({ chainId }) => parseInt(chainId, 16).toString()),
        showQrModal: true,
        rpcMap: rskChains.reduce((acc, { chainId, rpcUrls: [rpcUrl] }) => ({
              ...acc,
              [parseInt(chainId, 16)]: rpcUrl
            }), {})
      }
    },
    portis: {
      package: Portis,
      options: {
        id: "a1c8672b-7b1c-476b-b3d0-41c27d575920",
        network: {
          nodeUrl: supportedChains[0].rpcUrls[0],
          chainId: parseInt(supportedChains[0].chainId, 16),
        }
      }
    },
    torus: {
        package: Torus,
    },
    'custom-ledger': ledgerProviderOptions,
    'custom-dcent': dcentProviderOptions,
    'custom-trezor': {
      ...trezorProviderOptions,
      options: {
        manifestEmail: '[email protected]',
        manifestAppUrl: 'https://basic-sample.rlogin.identity.rifos.org/',
      }
    }
  },
  // single network list parameter
  ethereumChains: supportedChains,
})

We usually put this all together in a single file called rlogin.ts and export a single instance of RLogin. This ensures a single DOM element is created.

3. Connect!

import { providers } from 'ethers'

const login = () => rLogin.connect()
    .then(({ provider, disconnect }) => {
        const provider = new providers.Web3Provider(provider)
        provider.getSigner(0).getAddress().then(console.log)
    })

You can use provider with your client of preference: Web3.js, ethjs, ethers.js or other.

Use disconnect to disconnect from the selected wallet. This single function simplifies handling the wallet specifics at all.

Read the docs

Read more in our docs:

Run for development

Install dependencies - downloads and install dependencies from npm

npm i

Testing

Run tests - runs with jest

npm test

Lint - runs eslint syntax checks

npm run lint

Building

Build for production - builds umd into dist/main.js

npm run build

Build in watch mode - builds each time a file in src/ is updated

npm run build:dev

Serve the library - serves the library in http://localhost:5005

npm run serve

Metamask cannot be accessed without http - see https://ethereum.stackexchange.com/a/62217/620

The code

The key points:

  • src/RLogin.ts is the API. There we create the DOM element.
  • src/Core.ts handles the whole UX. It connects to the wallet, does the authentication, show the modal when triggered and so on.
  • src/ux has the different flows for the UX described. You will find step1 or confirmInformation
  • src/ui are the visual components of the rLogin
  • src/lib has the wallet specifics and authentication implementations

The rLogin depends on web3modal for some functionality. We imported and adapted part of the code to enable us expanding the UX.

Run the sample apps

This apps are built specifically for e2e testing but you can run them to test your changes. We also recommend to yarn link and use rLogin-sample-apps to test them too

Basic app (no backend) - serves the rLogin and the front-end

npm run sample:dapp

Open flavor - will run a backend with authentication installed

npm run sample:open

Permissioned flavor - will also request specific information and connect to the RIF Data Vault

npm run sample:permissioned

e2e eith Cypress

We use Cypress to do the e2e. The apps used to do it are described above. You will also find @rsksmart/mock-web3-provider, this is our Mock simulating Metamask.

To run the cypress e2e testing scripts, start the app using the permissioned flavor.

npm run sample:permissioned

Then in a new terminal, start the Cypress app and interact with the tests:

npm run cypress:open

The Cypress tests can also be run in a headless browser by running the command:

npm run cypress:run

Branching model

  • master has latest release. Merge into master will deploy to npm. Do merge commits.
  • develop has latest approved PR. PRs need to pass ci. Do squash & merge.
  • Use branches pointing to develop to add new PRs.
  • Do external PRs against latest commit in develop.

Disclaimer

Gas price calculation includes multiplication on 1.01 based on RSKIP09. While this is true for RSK, this operation may be unexpected if rLogin is used with other networks.