Tari Mainnet is live

active miners
active miners
active miners
< Back to lessonsWorking with Emoji Id

Working with Emoji Id

By Cayle Sharrock

The EmojiID struct in the tari_wallet crate provides everything you need to work with Tari's Emoji ID. In this tutorial, we will learn how to create an Emoji ID from a public key and vice versa. We will also validate an emoji ID against transcription errors.

use tari_wallet::util::emoji::EmojiId;
use tari_crypto::tari_utilities::hex::Hex;

fn main() {
    const EMOJI: &str = "πŸŽπŸ΄πŸŒ·πŸŒŸπŸ’»πŸ–πŸ©πŸΎπŸŒŸπŸ¬πŸŽ§πŸŒπŸ¦πŸ³πŸŽπŸπŸ’πŸ”‹πŸ‘•πŸŽΈπŸ‘ΏπŸ’πŸ“πŸŽ‰πŸ’”πŸŒΉπŸ†πŸ¬πŸ’‘πŸŽ³πŸš¦πŸΉπŸŽ’";
    const EMOJI_SHORT: &str = "πŸŽπŸ΄πŸŒ·πŸŒŸπŸ’»πŸ–πŸ©πŸΎπŸŒŸπŸ¬πŸŽ§πŸŒπŸ¦πŸ³πŸŽπŸπŸ’πŸ”‹πŸ‘•πŸŽΈπŸ‘ΏπŸ’πŸ“πŸŽ‰πŸ’”πŸŒΉπŸ†πŸ¬πŸ’‘πŸŽ³πŸš¦πŸΉ";

    // Convert a public key into its emoji ID
    let eid = EmojiId::from_hex("70350e09c474809209824c6e6888707b7dd09959aa227343b5106382b856f73a").unwrap();
    println!("{}",eid);

    // Convert an emoji to public key (in hex)
    let pubkey = EmojiId::str_to_pubkey(EMOJI).unwrap().to_hex();
    println!("{}", pubkey);

    //Test if both constants declared at the top are valid
    assert!(EmojiId::is_valid(EMOJI));
    assert_eq!(EmojiId::is_valid(EMOJI_SHORT), false, "Missing checksum");
    // TODO - check that emoji ID protects against transcription errors
    println!("It's all good!");
}
πŸ––πŸ₯΄πŸ˜πŸ™ƒπŸ’¦πŸ€˜πŸ€œπŸ‘πŸ™ƒπŸ™ŒπŸ˜±πŸ–πŸ™€πŸ€³πŸ––πŸ‘βœŠπŸˆβ˜‚πŸ’€πŸ‘šπŸ˜ΆπŸ€ŸπŸ˜³πŸ‘’πŸ˜˜πŸ˜ΊπŸ™ŒπŸŽ©πŸ€¬πŸΌπŸ˜ŽπŸ₯Ί
70350e09c474809209824c6e6888707b7dd09959aa227343b5106382b856f73a
It's all good!