Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@iota/validators

Package Overview
Dependencies
Maintainers
6
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@iota/validators

Collection of guards and validators, useful in IOTA development.

  • 1.0.0-beta.30
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
13K
increased by7.29%
Maintainers
6
Weekly downloads
 
Created
Source

@iota/validators

Collection of guards and validators, useful in IOTA development.

Installation

Instal using npm:

npm install @iota/validators

or using yarn:

yarn add @iota/validators

API Reference

validators.isAddress(address)

Summary: Validates the checksum of the given address.

ParamTypeDescription
addressstringAddress with a checksum

This method takes an address with a checksum and validates that the checksum is correct.

To generate a new address with a checksum, use the getNewAddress() method.

Returns: boolean - valid - Whether the checksum is valid
Example

let valid = Validator.isAddress('9FNJWLMBECSQDKHQAGDHDPXBMZFMQIMAFAUIQTDECJVGKJBKHLEBVU9TWCTPRJGYORFDSYENIQKBVSYKW9NSLGS9UW');

validators~isTrits(input)

ParamType
inputany

Checks if input is an Int8Array of trit values; -1, 0, 1.

validators~isNullTrits(trits)

ParamType
tritsInt8Array

Checks if trits are NULL.

validators~isTrytes(trytes, [length])

ParamTypeDefault
trytesstring
[length]string | number"'1,'"

Checks if input is correct trytes consisting of [9A-Z]; optionally validate length

validators~isTrytesOfExactLength(trytes, length)

ParamType
trytesstring
lengthnumber

validators~isTrytesOfMaxLength(trytes, length)

ParamType
trytesstring
lengthnumber

validators~isEmpty(hash)

ParamType
hashstring

Checks if input contains 9s only.

validators~isHash(hash)

ParamType
hashstring

Checks if input is correct hash (81 trytes) or address with checksum (90 trytes)

validators~isInput(address)

ParamType
addressstring

Checks if input is valid input object. Address can be passed with or without checksum. It does not validate the checksum.

validators~isTag(tag)

ParamType
tagstring

Checks that input is valid tag trytes.

validators~isTransfer(transfer)

ParamType
transferTransfer

Checks if input is valid transfer object.

validators~isUri(uri)

ParamType
uristring

Checks that a given URI is valid

Valid Examples:

  • udp://[2001:db8:a0b:12f0::1]:14265
  • udp://[2001:db8:a0b:12f0::1]
  • udp://8.8.8.8:14265
  • udp://domain.com
  • udp://domain2.com:14265

validators~validate()

Throws:

  • Error error

Runs each validator in sequence, and throws on the first occurence of invalid data. Validators are passed as arguments and executed in given order. You might want place validate() in promise chains before operations that require valid inputs, taking advantage of built-in promise branching.

Example

try {
  validate([
    value, // Given value
    isTrytes, // Validator function
    'Invalid trytes' // Error message
  ])
} catch (err) {
  console.log(err.message) // 'Invalid trytes'
}

Keywords

FAQs

Package last updated on 18 Jun 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc