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

@talismn/siws

v0.0.19

Published

Sign-In with Substrate

Downloads

1,240

Readme

SIWS Example

Sign-In with Substrate

@talismn/siws is a package that lets you easily allow users to authenticate themselves with your off chain services by signing in with their Substrate accounts.

Problem & Motivation

When building Signet, an enterprise tool for companies to manage their on-chain organisations in the Substrate ecosystem, we needed a way for users to prove that they own an address before they can request for resources relevant to that address. There was no solution yet that offered good user experience, where users could easily understand what they are signing with their wallet. Inspired by Sign-in with Ethereum, we decided to build the right tool for the Substrate ecosystem.

Features

  • Construct human readable sign in message
  • Construct message in stringified JSON format
  • Decode and parse string message of both format into JS object
  • Basic validations (e.g. expiration)
  • Utility Address to help with dealing with address string
  • Utility verifySIWS to help verify that a signature is valid
  • Full Typescript support

Installation

$ npm install @talismn/siws

Usage

Frontend

// 1. import necessary modules
import { web3FromSource } from "@polkadot/extension-dapp"
import { SiwsMessage } from "@talismn/siws"

// 2. handle sign in after `account` is selected
const handleSignIn = async () => {
  const siws = new SiwsMessage({
    domain: "localhost",
    uri: "http://localhost:3000/sign-in",
    address: account.address,
    nonce, // a challenge generated from backend
    statement: "Welcome to my dapp!",
  })

  // get the injector so we can sign the message
  const injectedExtension = await web3FromSource(account.meta.source)
  const signed = await siws.sign(injectedExtension)

  // api to sign in with backend
  await signIn(signed)
}

Backend

// 1. import siws
import { verifySIWS } from "@talismn/siws"

// 2. backend handler to handle sign in request
const handleSignInRequest = ({ signature, message, address }) => {
  // verify that signature is valid
  const siwsMessage = await verifySIWS(message, signature, address)

  // ... user has proven ownership of address and hence authenticated!
}

Documentation

Check out our full guide on how to implement SIWS into your dapp!

Support