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

@tria-sdk/authenticate-web

v2.0.20

Published

## The Tria Authentication SDK provides an easy way to integrate authentication into your web applications. It includes features such as login, logout, and account management.

Downloads

883

Readme

Tria Authentication SDK

The Tria Authentication SDK provides an easy way to integrate authentication into your web applications. It includes features such as login, logout, and account management.

Installation

To install the SDK, use the following command:

    npm install @tria-sdk/authenticate-web

    yarn add @tria-sdk/authenticate-web

Usage

Importing the AuthManager

First, import the AuthManager class from the SDK:

    import { AuthManager } from '@tria-sdk/authenticate-web';

Initializing the AuthManager

Create an instance of the AuthManager with the required options:

    const authManager = new AuthManager({
    darkMode: true, // Optional: Enable dark mode (default: false)
    triaStaging?: false, // Optional: Use trias staging environment (default: false)
    dappName: 'Your Dapp Name', // Required: Your Dapp's name
    logo: 'https://example.com/logo.svg', // Required: URL to your Dapp's logo
    clientId?: 'your-client-id', // Required: Your Tria client ID for analytics
    metaToken: 'your-meta-token', // Required: Your Tria meta token provided by tria
});

Configure the AuthManager

The TriaConfigOptions interface allows you to configure the following properties:

configure web 3 settings


   authManager.configure({
     chain: "MUMBAI",
     environment: "mainnet",
     aa: {
        supportAa: boolean;
        pimlicoApiKey?: string;
        isSponsored?: boolean;
        sponsorshipPolicyId?: string;
        sponsorshipPolicyIds?: ChainNameToPolicyId;
     },
     rpcUrl: "https://my-rpc-url.com/",
     dappDetails:{
        dappDomain?: string;
        dappLogo?: string;
     }
   });

Using AuthManager Methods

Login

To prompt the user to log in, call the login method:

authManager.login();

Logout

To log the user out, call the disconnect method:

await authManager.disconnect();

Get Account

To get the user's account information, call the getAccount method:

const account = authManager.getAccount();

This method returns an Account object with the following properties:

triaName: The user's Tria username.
evm: An object containing the user's EVM-compatible address.
nonEvm: An object containing the user's non-EVM-compatible address.

Check Authentication Status

To check if the user is authenticated, call the isAuthenticated method:

const isAuthenticated = authManager.isAuthenticated();

This method returns a boolean indicating whether the user is logged in.

Send Transaction

To send a transaction, call the send method with the amount, recipient address, and optional token address:

await authManager.send(amount, recipientAddress, tokenAddress);

Sign Message

To sign a message, call the signMessage method with the message:

const signature = await authManager.signMessage(message);

Write Contract

To write to a smart contract, call the writeContract method with the contract details and optional payment token:

await authManager.writeContract(contractDetails, payToken);

Read Contract

To read from a smart contract, call the readContract method with the contract details:

const result = await authManager.readContract(contractDetails);

Event Listeners

You can listen to login and logout events by adding event listeners:

authManager.addEventListener('TRIA_LOGIN', (event) => {
// Handle login event
});

authManager.addEventListener('TRIA_LOGOUT', (event) => {
// Handle logout event
});

Removing Event Listeners

To remove an event listener, use the removeEventListener method:

authManager.removeEventListener('TRIA_LOGIN', loginHandler);
authManager.removeEventListener('TRIA_LOGOUT', logoutHandler);

Usage

ensure that you build dependency packages in the following order

  • build the chains package
  • build the utils package
  • build the connect package

run install in folder root

    pnpm install

explanation of the build process

"scripts": {
    "dev": "concurrently \"pnpm:vite\" \"pnpm:tw\" \"pnpm:tw-lit\"",
    "vite": "tsc && vite",
    "build": "tsc && vite build",
    "preview": "vite preview",
    "tailwind": "concurrently \"pnpm:tw\" \"pnpm:tw-lit\"",
    "tw": "tailwindcss -i ./src/styles/tailwind.css -o ./src/styles/tw.css --watch",
    "tw-lit": "npx twlitme --input ./src/styles/tw.css --output ./src/styles/tailwind.ts --watch"
  },

The sdk itself renders a (web component)[https://lit.dev/], that uses the lit element framework to create it. Tailwind cannot be directly used here so the tw command first compiles tailwind classes used in the project to css then tw-lit converts it to javascript css which is then loaded onto the project.

The build uses vite and outputs an mjs file which is a ES Module.