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

@iota/checksum

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/checksum

Add, remove and validate checksums

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

Version published
Weekly downloads
9.9K
decreased by-1.69%
Maintainers
6
Weekly downloads
 
Created
Source

@iota/checksum

Add, remove and validate checksums.

Installation

Install using npm:

npm install @iota/checksum

or using yarn:

yarn add @iota/checksum

API Reference

checksum.addChecksum(input, [checksumLength], [isAddress])

Summary: Generates a checksum and appends it to the given trytes.
Throws:

  • errors.INVALID_ADDRESS : Make sure that the given address is 90 trytes long.
  • errors.INVALID_TRYTES : Make sure that the input argument contains only trytes
  • errors.INVALID_CHECKSUM_LENGTH : Make sure that the checksumLength argument is a number greater than or equal to 3. If the isAddress argument is set to true, make sure that the checksumLength argument is 9.
ParamTypeDefaultDescription
inputstring81 trytes to which to append the checksum
[checksumLength]number9Length of the checksum to generate
[isAddress]booleantrueWhether the input is an address

This method takes 81 trytes, which could be an address or a seed, generates the checksum and appends it to the trytes.

To generate a checksum that is less than 9 trytes long, make sure to set the isAddress argument to false.

To generate an address, use the getNewAddress() method.

Returns: string - The original trytes with an appended checksum.
Example

let addressWithChecksum = Checksum.addChecksum('ADDRESS...');

checksum.removeChecksum(input)

Summary: Removes the checksum from the given address.
Throws:

  • errors.INVALID_ADDRESS : Make sure that the given address is 90 trytes long.
ParamTypeDescription
inputstringAddress from which to remove the checksum

This method takes an address of 90 trytes, and removes the last 9 trytes to return the address without a checksum.

To generate an address, use the getNewAddress() method. To add a checksum to an address, use the addChecksum() method.

Returns: string - The original address without the appended checksum.
Example

let addressWithoutChecksum = Checksum.removeChecksum('ADDRESS...');

checksum.isValidChecksum(addressWithChecksum)

Summary: Validates the checksum of an address.
Throws:

  • errors.INVALID_ADDRESS : Make sure that the given address is 90 trytes long.
ParamTypeDescription
addressWithChecksumstringAddress with a checksum

This method takes an address of 90 trytes, and checks if the checksum is valid.

To generate an address, use the getNewAddress() method. To add a checksum to an address, use the addChecksum() method.

Returns: boolean - Whether the checksum is valid.
Example

let valid = Checksum.isValidChecksum('ADDRESS...');

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