0.2.1 โ€ข Published 3 years ago

hemoji v0.2.1

Weekly downloads
7
License
MIT
Repository
github
Last release
3 years ago

Hemoji

A visual hashing library with Emojis ๐Ÿช โ›“๏ธ ๐ŸŒ ๐Ÿšœ

Version Downloads License Issues Vulnerabilities

Hemoji on NPM

Hemoji is a small single function JavaScript/TypeScript library that hashes a string into a sequence of emojis. Just like hashes, two identical strings passed through Hemoji will produce the same result.

This library is not intended to replace traditional hashing functions as collision are more likely. But as it provides more possibilities than alphanumeric characters for its length, it makes it a more convenient method to compare two pieces of information where it would not be possible, practical or secure to do so programmatically. Examples would include oral confirmation between two people or self confirmation in separate contexts, i.e., across separate devices.

You can try Hemoji online or continue reading on how to use it.

This is inspired by Telegram's emoji key verification feature on calls.

Getting started

Install the library using NPM:

npm i hemoji

Or Yarn:

yarn add hemoji

The library exports a single function (as default):

import hemoji from 'hemoji';
// OR
const hemoji = require('hemoji').default;

And use it!

hemoji('hemoji'); // ๐Ÿช• ๐ŸŽถ ๐Ÿฆ’ ๐ŸŽ  ๐Ÿ’ ๐ŸŒ—
hemoji('Hello world', { length: 8 }); // ๐ŸŽŸ๏ธ ๐Ÿค ๐Ÿ•Œ ๐ŸŸฆ ๐Ÿ“› ๐Ÿ”น ๐Ÿ”ช ๐Ÿš
hemoji('Hello world', { length: 4 }); // ๐Ÿ“Œ ๐Ÿงพ โžฟ ๐ŸฅŒ

The first parameter is the string you wish to hash. The second (optional) parameter is an options object (see below).

Options

NameTypeDescriptionDefault Value
version'v1'Version of emoji set (based on versions.json)'v1'
lengthnumberNumber of emojis to display in the result6
spacerstringSpacing character for the result' ' (space)

How does it work?

  1. The input string gets hashed to SHA-256.
  2. The hashed result gets split into a few chunks.
  3. The emoji index array is calculated from the chunk using a modulo of the emoji index array of the decimal value of the chunk.
  4. The result of each chunk is concatenated and returned.

Other languages

There are no other implementation of Hemoji as of yet. If you implemented it in a different language, please let me know and I will add it here.

Please note that implementation in other languages have to produce the same result as this library. Refer to the versions.json file for the exact list of emojis this library is using as well as the unit tests to verify the results.

License

This project is licensed under the MIT License.

0.2.1

3 years ago

0.2.0

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago