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

universal-qr-scanner

v1.1.6

Published

Provides a QR scanner that supports paying to fiat account from web3 wallet

Downloads

342

Readme

Universal QR Scanner

This project is a npm package that provides React components and contexts for Solana chain QR payment services, that is built on top of Portal wallet and other service partners.

We provide a QR scanner for you to integrate into your wallet, that helps your wallet do payment and transfer:

  • to Solana address
  • via Solana Pay
  • to fiat-accepting account

UI Demo Project

Demo Project

Supports

Next.js

Get Started

To Install:

npm i universal-qr-scanner
yarn add universal-qr-scanner

Include a next.config.mjs in your root

/** @type {import('next').NextConfig} */
const nextConfig = {
  env: {
    portalClientApiKey: process.env.PORTAL_CLIENT_API_KEY,
    solMint: 'So11111111111111111111111111111111111111112',
    solanaChainId: 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp',                   // Mainnet
    pyUsdMint: '2b1kV6DkPAnxd5ixfnxCpjxmKwqjjaYmCZfHsFu24GXo',                  // Mainnet
    solanaRpcUrl:
      'https://mainnet.helius-rpc.com/?api-key=' + process.env.HELIUS_API_KEY,  // Mainnet
    // solanaChainId: 'solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1',                // Dev net
    // pyUsdMint: 'CXk2AMBfi3TwaEL2468s6zP8xq9NxTXjp9gjMgzeUynM',               // Dev net
    // solanaRpcUrl: 'https://api.devnet.solana.com',                           // Dev net
  },
};

export default nextConfig;

Two keys are need in the .env

PORTAL_CLIENT_API_KEY=YOU_KEY_HERE
HELIUS_API_KEY=YOU_KEY_HERE

Set up Route Handlers or API Routes in your project

PORTAL's sample

Wrap PortalProvider and PayProvider around your project root.

import { PortalProvider, PayProvider } from 'universal-qr-scanner';

    <PortalProvider>
      <PayProvider>
        {children}
      </PayProvider>
    </PortalProvider>

On your page, import the PayUI Component, you are now all set to use payment functions in your wallet!

import { usePay, PayUI } from 'universal-qr-scanner';
import React from 'react';

const Scan = () => {
  const payCrypto = usePay();

  return <PayUI payCrypto={payCrypto} />;
};

export default Scan;

To view the payment transactions you made, use

  const payCrypto = usePay();
  const txns = await payCrypto.getPaymentTransactions();

Build Your Own UI

Without using the PayUI component that we build, you can also build your own UI with the following core functions from usePay().

  • reset()
    • resets to the initial state
  • decode()
    • decode the raw QR data, identifies the embedded information and set the state accordingly
  • updateFields()
    • update the states to get ready to initialize a payment, such as token amount, fiat amount and memo description
  • pay()
    • sends the transaction with the encrypted memo field on chain
  • getPaymentTransactions()
    • look on chain, identify, validate, decrypt and returns payment transactions made previously through Universal QR Scanner

Payment Transaction Metadata

In order to differentiate a payment transaction made with our service, apart from the other on-chain activities, we designed a way to identify and validate those payment transactions. For payment transactions made through Universal QR Scanner, they have a memo field attached, which contains:

  • an identifier prefix for us to quickly locate it
  • an encrypted information on the payment details such as payment type and fiat information (currency, amount)

For example: alt text

We use AES-256-CBC symmetric encryption with HMAC-SHA256 authentication. The data can be encrypted and decrypted using the same key, which in this case, the API key provided by PORTAL. The same key will used to decrypt the memo field data in payCrypto.getPaymentTransactions(). In this way, we can validate the authencity of the payment transaction and prevent any attempts at impersonating a transaction.

The actual data for the one above looks like this: alt text