@biolimitless/signature-validators
TypeScript icon, indicating that this package has built-in type declarations

0.2.2 • Public • Published

@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')
  }
}

Readme

Keywords

Package Sidebar

Install

npm i @biolimitless/signature-validators

Weekly Downloads

0

Version

0.2.2

License

MIT

Unpacked Size

17.9 kB

Total Files

23

Last publish

Collaborators

  • jumojet5
  • martushka