Skip to content

Instantly share code, notes, and snippets.

@ardislu
Last active June 19, 2024 07:14
Show Gist options
  • Save ardislu/c2626b5f524cfc94142e33e055bb4516 to your computer and use it in GitHub Desktop.
Save ardislu/c2626b5f524cfc94142e33e055bb4516 to your computer and use it in GitHub Desktop.
Minimal JavaScript implementation of ERC-7673.
// Utility functions to convert an Ethereum hexadecimal address to base256emoji and vice versa.
// https://ercs.ethereum.org/ERCS/erc-7673
const toEmoji = [
'๐Ÿš€', '๐Ÿช', 'โ˜„', '๐Ÿ›ฐ', '๐ŸŒŒ', '๐ŸŒ‘', '๐ŸŒ’', '๐ŸŒ“', '๐ŸŒ”', '๐ŸŒ•', '๐ŸŒ–', '๐ŸŒ—', '๐ŸŒ˜', '๐ŸŒ', '๐ŸŒ', '๐ŸŒŽ',
'๐Ÿ‰', 'โ˜€', '๐Ÿ’ป', '๐Ÿ–ฅ', '๐Ÿ’พ', '๐Ÿ’ฟ', '๐Ÿ˜‚', 'โค', '๐Ÿ˜', '๐Ÿคฃ', '๐Ÿ˜Š', '๐Ÿ™', '๐Ÿ’•', '๐Ÿ˜ญ', '๐Ÿ˜˜', '๐Ÿ‘',
'๐Ÿ˜…', '๐Ÿ‘', '๐Ÿ˜', '๐Ÿ”ฅ', '๐Ÿฅฐ', '๐Ÿ’”', '๐Ÿ’–', '๐Ÿ’™', '๐Ÿ˜ข', '๐Ÿค”', '๐Ÿ˜†', '๐Ÿ™„', '๐Ÿ’ช', '๐Ÿ˜‰', 'โ˜บ', '๐Ÿ‘Œ',
'๐Ÿค—', '๐Ÿ’œ', '๐Ÿ˜”', '๐Ÿ˜Ž', '๐Ÿ˜‡', '๐ŸŒน', '๐Ÿคฆ', '๐ŸŽ‰', '๐Ÿ’ž', 'โœŒ', 'โœจ', '๐Ÿคท', '๐Ÿ˜ฑ', '๐Ÿ˜Œ', '๐ŸŒธ', '๐Ÿ™Œ',
'๐Ÿ˜‹', '๐Ÿ’—', '๐Ÿ’š', '๐Ÿ˜', '๐Ÿ’›', '๐Ÿ™‚', '๐Ÿ’“', '๐Ÿคฉ', '๐Ÿ˜„', '๐Ÿ˜€', '๐Ÿ–ค', '๐Ÿ˜ƒ', '๐Ÿ’ฏ', '๐Ÿ™ˆ', '๐Ÿ‘‡', '๐ŸŽถ',
'๐Ÿ˜’', '๐Ÿคญ', 'โฃ', '๐Ÿ˜œ', '๐Ÿ’‹', '๐Ÿ‘€', '๐Ÿ˜ช', '๐Ÿ˜‘', '๐Ÿ’ฅ', '๐Ÿ™‹', '๐Ÿ˜ž', '๐Ÿ˜ฉ', '๐Ÿ˜ก', '๐Ÿคช', '๐Ÿ‘Š', '๐Ÿฅณ',
'๐Ÿ˜ฅ', '๐Ÿคค', '๐Ÿ‘‰', '๐Ÿ’ƒ', '๐Ÿ˜ณ', 'โœ‹', '๐Ÿ˜š', '๐Ÿ˜', '๐Ÿ˜ด', '๐ŸŒŸ', '๐Ÿ˜ฌ', '๐Ÿ™ƒ', '๐Ÿ€', '๐ŸŒท', '๐Ÿ˜ป', '๐Ÿ˜“',
'โญ', 'โœ…', '๐Ÿฅบ', '๐ŸŒˆ', '๐Ÿ˜ˆ', '๐Ÿค˜', '๐Ÿ’ฆ', 'โœ”', '๐Ÿ˜ฃ', '๐Ÿƒ', '๐Ÿ’', 'โ˜น', '๐ŸŽŠ', '๐Ÿ’˜', '๐Ÿ˜ ', 'โ˜',
'๐Ÿ˜•', '๐ŸŒบ', '๐ŸŽ‚', '๐ŸŒป', '๐Ÿ˜', '๐Ÿ–•', '๐Ÿ’', '๐Ÿ™Š', '๐Ÿ˜น', '๐Ÿ—ฃ', '๐Ÿ’ซ', '๐Ÿ’€', '๐Ÿ‘‘', '๐ŸŽต', '๐Ÿคž', '๐Ÿ˜›',
'๐Ÿ”ด', '๐Ÿ˜ค', '๐ŸŒผ', '๐Ÿ˜ซ', 'โšฝ', '๐Ÿค™', 'โ˜•', '๐Ÿ†', '๐Ÿคซ', '๐Ÿ‘ˆ', '๐Ÿ˜ฎ', '๐Ÿ™†', '๐Ÿป', '๐Ÿƒ', '๐Ÿถ', '๐Ÿ’',
'๐Ÿ˜ฒ', '๐ŸŒฟ', '๐Ÿงก', '๐ŸŽ', 'โšก', '๐ŸŒž', '๐ŸŽˆ', 'โŒ', 'โœŠ', '๐Ÿ‘‹', '๐Ÿ˜ฐ', '๐Ÿคจ', '๐Ÿ˜ถ', '๐Ÿค', '๐Ÿšถ', '๐Ÿ’ฐ',
'๐Ÿ“', '๐Ÿ’ข', '๐ŸคŸ', '๐Ÿ™', '๐Ÿšจ', '๐Ÿ’จ', '๐Ÿคฌ', 'โœˆ', '๐ŸŽ€', '๐Ÿบ', '๐Ÿค“', '๐Ÿ˜™', '๐Ÿ’Ÿ', '๐ŸŒฑ', '๐Ÿ˜–', '๐Ÿ‘ถ',
'๐Ÿฅด', 'โ–ถ', 'โžก', 'โ“', '๐Ÿ’Ž', '๐Ÿ’ธ', 'โฌ‡', '๐Ÿ˜จ', '๐ŸŒš', '๐Ÿฆ‹', '๐Ÿ˜ท', '๐Ÿ•บ', 'โš ', '๐Ÿ™…', '๐Ÿ˜Ÿ', '๐Ÿ˜ต',
'๐Ÿ‘Ž', '๐Ÿคฒ', '๐Ÿค ', '๐Ÿคง', '๐Ÿ“Œ', '๐Ÿ”ต', '๐Ÿ’…', '๐Ÿง', '๐Ÿพ', '๐Ÿ’', '๐Ÿ˜—', '๐Ÿค‘', '๐ŸŒŠ', '๐Ÿคฏ', '๐Ÿท', 'โ˜Ž',
'๐Ÿ’ง', '๐Ÿ˜ฏ', '๐Ÿ’†', '๐Ÿ‘†', '๐ŸŽค', '๐Ÿ™‡', '๐Ÿ‘', 'โ„', '๐ŸŒด', '๐Ÿ’ฃ', '๐Ÿธ', '๐Ÿ’Œ', '๐Ÿ“', '๐Ÿฅ€', '๐Ÿคข', '๐Ÿ‘…',
'๐Ÿ’ก', '๐Ÿ’ฉ', '๐Ÿ‘', '๐Ÿ“ธ', '๐Ÿ‘ป', '๐Ÿค', '๐Ÿคฎ', '๐ŸŽผ', '๐Ÿฅต', '๐Ÿšฉ', '๐ŸŽ', '๐ŸŠ', '๐Ÿ‘ผ', '๐Ÿ’', '๐Ÿ“ฃ', '๐Ÿฅ‚'
];
const fromEmoji = {};
for (const [index, emoji] of toEmoji.entries()) {
fromEmoji[emoji] = index.toString(16).padStart(2, '0');
}
function encodeAddress(hex) {
return hex.replace('0x', '').match(/.{2}/g).map(i => toEmoji[parseInt(i, 16)]).join('');
}
// emoji.split('') will split the string into an array of UTF-16 code units, which are neither
// grapheme clusters nor Unicode code points. Use Intl.Segmenter() to split into grapheme clusters.
function decodeAddress(emoji) {
const segmenter = new Intl.Segmenter();
return `0x${[...segmenter.segment(emoji)].map(e => fromEmoji[e.segment]).join('')}`;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment