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

@biolimitless/signature-validators

v0.2.2

Published

signature validators utils

Downloads

8

Readme

@biolimitless/signature-validators

Install

npm i @biolimitless/signature-validators

Utils

For validate existed signatures use these utils.

For ethereum networks

function validateEvmSignature(
  signature: string,
  message: string,
  account: Address,
): boolean

ⓘ Info

Validating the message signed by personal_sign method

For tron networks

function validateTvmSignature(
  tronWeb: LimitedTronWeb,
  signature: string,
  message: string,
  account: Address,
): Promise<boolean>

ⓘ Info

Tron has two methods for sign message sign and signMessageV2. Our api firstly validates signature by verifyMessageV2 (for signMessageV2 method) and after that if v2 not valid use verifyMessage (for sign method)

⚠️ Attention

Tron signature could be validated only by validateTvmSignature and ethereum signature only by validateEvmSignature

Usage example:

// for evm sign
async function signSomething() {
  const message = 'test message'
  const connector = new MetamaskConnector(supportedNetworks, activeChainIds[0], activeChainIds)
  await connector.connect()
  const account = connector.account
  const signature = await connector.signMessage(message)
  await sendSignature(signature, message, account.toHex(), 'evm') // some backend endpoint for validate signature
}

// for tvm sign
async function signSomething() {
  const message = 'test message'
  const connector = new TronConnector(TvmChainIdsEnum.MAINNET)
  await connector.connect()
  const account = connector.account
  const signature = await connector.signMessage(message)
  await sendSignature(signature, message, account.toBase58(), 'tvm') // some backend endpoint for validate signature
}

/*
 for validate on backend

 for example 1
     signature - '0x6be779db421a2d3b2ddfb2f883a7589ee34a2c793269bdd776c17721471f4d1563ccf1c58fc902497559bc6591726cb1ad90e87f6cf4f6c04019a3e9e8c240c11b
     message - 'test message'
     account - 'TTgJKmrBrpjNh2gKYuYaBscEPmG3PucBAr'
 result true

 for example2
     signature - '0xcf8df093455d31dbf28142e8adbb4c341c74da9abff15ec5bef350283246f6e22e1cb218f66a9f7179ae73763f46d08ce4b8879d5fb41be709202d2e3a7f94841b
     message - 'test message'
     account - '0x47F110C21FE169c2728cFE5C075b38CA1Bdf476e'
 result true
 */
async function validateSign(signature: string, message: string, account: string, type: 'evm' | 'tvm') {
  switch (type) {
    case 'evm':
      return validateTvmSignature(signature, message, Address.from(account))
    case 'tvm':
      return validateEvmSignature(signature, message, Address.from(account))
    default:
      throw new Error('Unknown type')
  }
}