Socket
Socket
Sign inDemoInstall

@iota/converter

Package Overview
Dependencies
1
Maintainers
6
Versions
40
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @iota/converter

Convert values & trytes to trits and back


Version published
Weekly downloads
2.3K
increased by2.38%
Maintainers
6
Install size
711 kB
Created
Weekly downloads
 

Readme

Source

@iota/converter

Methods for converting ascii, values & trytes to trits and back.

Installation

Install using npm:

npm install @iota/converter

or using yarn:

yarn add @iota/converter

API Reference

converter.asciiToTrytes(input)

Summary: Converts ASCII characters to trytes.
Throws:

  • errors.INVALID_ASCII_CHARS : Make sure that the input argument contains only valid ASCII characters.
ParamTypeDescription
inputstringASCII input

This method converts ASCII characters to trytes.

To convert trytes to ASCII characters, use the trytesToAscii() method.

Returns: string - Trytes
Example

let trytes = Converter.asciiToTrytes('Hello, where is my coffee?');

converter.trytesToAscii(trytes)

Summary: Converts trytes to ASCII characters.
Throws:

  • errors.INVALID_TRYTES : Make sure that the trytes argument contains only valid trytes (A-Z or 9).
  • errors.INVALID_ODD_LENGTH : Make sure that the trytes argument contains an even number of trytes.
ParamTypeDescription
trytesstringAn even number of trytes

This method converts trytes to ASCII characters.

Because each ASCII character is represented as 2 trytes, the given trytes must be of an even length.

To convert ASCII characters to trytes, use the asciiToTrytes() method.

Returns: string - ASCII characters
Example

let message = Converter.trytesToAscii('IOTA');

converter.trytesToTrits(input)

Summary: Converts trytes to trits.
Throws:

  • errors.INVALID_TRYTES : Make sure that the input argument contains only valid trytes (A-Z or 9).
ParamTypeDescription
inputString | numberTrytes

This method converts trytes to trits.

To convert ASCII characters to trytes, use the asciiToTrytes() method.

Returns: Int8Array - trits
Example

let trits = Converter.trytesToTrits('IOTA');

converter.tritsToTrytes(input)

Summary: Converts trits to trytes.
Throws:

  • errors.INVALID_TRITS : Make sure that the input argument contains an array of trits.
ParamTypeDescription
inputString | numberTrits

This method converts trits to trytes.

To convert trytes to ASCII characters, use the trytesToAscii() method.

Returns: Int8Array - trytes
Example

let trytes = Converter.tritsToTrytes(trits);

converter.tritsToValue(input)

Summary: Converts trits to a number.

ParamTypeDescription
inputString | numberTrits

This method converts trits to a number.

To convert trytes to trits, use the trytesToTrits() method. To convert trits to trytes, use the tritsToTrytes() method.

Returns: Int8Array - number
Example

let number = Converter.tritsToValue(trits);

converter.valueToTrits(input)

Summary: Converts trits to a number.

ParamTypeDescription
inputString | numberNumber

This method converts a number to trits.

To convert trits to trytes, use the tritsToTrytes() method.

Returns: Int8Array - trits
Example

let trits = Converter.valueToTrits(9);

Keywords

FAQs

Last updated on 18 Jun 2020

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc