By Cayle Sharrock

Working with Emoji Id

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);
    let pubkey = EmojiId::str_to_pubkey(EMOJI).unwrap();
    println!("{}", pubkey.to_hex());
    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!