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.
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).
Name | Type | Description | Default Value |
---|---|---|---|
version | 'v1' | Version of emoji set (based on versions.json ) |
'v1' |
length | number | Number of emojis to display in the result | 6 |
spacer | string | Spacing character for the result | ' ' (space) |
- The input string gets hashed to SHA-256.
- The hashed result gets split into a few chunks.
- The emoji index array is calculated from the chunk using a modulo of the emoji index array of the decimal value of the chunk.
- The result of each chunk is concatenated and returned.
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.
This project is licensed under the MIT License.