tuupola/trytes

Trytes encoder and decoder for arbitrary data

0.1.0 2017-12-10 16:29 UTC

This package is auto-updated.

Last update: 2024-03-10 03:36:44 UTC


README

This library implements Trytes encoding as described by IOTA project. Trytes are equivalent of bytes but in ternary number system.

Latest Version Software License Build Status Coverage

Install

Install with composer.

$ composer require tuupola/trytes

Usage

$trytes = new Tuupola\Trytes;

$encoded = $trytes->encode(random_bytes(128));
$decoded = $trytes->decode($encoded);

Character sets

By default this library uses the IOTA style character set. Shortcut is provided also for Heptavintimal characters. If required you can use any custom character set of 27 unique characters.

use Tuupola\Trytes;

print Trytes::IOTA; /* 9ABCDEFGHIJKLMNOPQRSTUVWXYZ */
print Trytes::HEPTAVINTIMAL; /* 0123456789ABCDEFGHKMNPRTVXZ */

$default = new Trytes(["characters" => Trytes::IOTA]);
$heptavintimal = new Trytes(["characters" => Trytes::HEPTAVINTIMAL]);
print $default->encode("Hello world!"); /* RBTC9D9DCDEAKDCDFD9DSCFA */
print $heptavintimal->encode("Hello world!"); /* K2N304043451B4346404M361 */

Static Proxy

If you prefer to use static syntax use the provided static proxy.

use Tuupola\TrytesProxy as Trytes;

$encoded = Trytes::encode(random_bytes(128));
$decoded = Trytes::decode($encoded);

Testing

You can run tests either manually or automatically on every code change. Automatic tests require entr to work.

$ make test
$ brew install entr
$ make watch

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email tuupola@appelsiini.net instead of using the issue tracker.

License

The MIT License (MIT). Please see License File for more information.