Skip to content

Commit ad1add5

Browse files
committed
feat: basic emoji work
1 parent 981c9be commit ad1add5

File tree

3 files changed

+132
-1
lines changed

3 files changed

+132
-1
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"scripts": {
1313
"start": "ts-node src/demo.ts",
1414
"dev": "ts-node src/demo.ts",
15+
"emoji": "ts-node src/emoji.ts",
1516
"build": "tsc",
1617
"test": "jest",
1718
"lint": "eslint src/. --ext ts --ext tsx --ext js",

src/demo.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { defaultAbiCoder, keccak256 } from "ethers/lib/utils";
22
import { toSvg } from "jdenticon";
33
import fromTargetAndCalldataToHash from "./fromCalldataAndAbi";
4+
import fromHexStringToEmojiString from "./emoji";
45

56

67
// From Metamask to The whole thing
@@ -27,4 +28,7 @@ console.log(keccak256(defaultAbiCoder.encode(["address"], ["0x3Fa73f1E5d8A792C80
2728
// ABI
2829
// Calldata
2930

30-
console.log("Full send", fromTargetAndCalldataToHash("0x3Fa73f1E5d8A792C80F426fc8F84FBF7Ce9bBCAC", ["function lock(address _account, uint256 _amount) external"], "0x282d3fdf000000000000000000000000b1c05e80678bbcdf8fbca2b4820164313e4867d6000000000000000000000000000000000000000000000034f69370b524873a1f"))
31+
const asDigest = fromTargetAndCalldataToHash("0x3Fa73f1E5d8A792C80F426fc8F84FBF7Ce9bBCAC", ["function lock(address _account, uint256 _amount) external"], "0x282d3fdf000000000000000000000000b1c05e80678bbcdf8fbca2b4820164313e4867d6000000000000000000000000000000000000000000000034f69370b524873a1f")
32+
33+
console.log("From String to Hash", asDigest)
34+
console.log("From String to Emojis", fromHexStringToEmojiString(asDigest))

src/emoji.ts

+126
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
// Given a Hash
2+
// Represent it in a sequence of emojis
3+
4+
// Manually gone and looked at different shapes
5+
// Skipping emojis that look too similar
6+
// NOTE: I could have searched way more
7+
// I have yet to go through https://emojipedia.org/food-drink and onwards
8+
const ARBITRARY_LIST_OF_EMOJIS = [
9+
"🌲",
10+
"🍄",
11+
"🌸",
12+
"🌹",
13+
"🌓",
14+
"🪐",
15+
"⭐",
16+
"🌤️",
17+
"🌀",
18+
"🌈",
19+
"🌊",
20+
"🤠",
21+
"🥳",
22+
"😎",
23+
"🤯",
24+
"🤮",
25+
"😈",
26+
"💀",
27+
"💩",
28+
"🤡",
29+
"👺",
30+
"👻",
31+
"👽",
32+
"👾",
33+
"🤖",
34+
"😻",
35+
"🙈",
36+
"👍",
37+
"👊",
38+
"🤝",
39+
"🙏",
40+
"💅",
41+
"💪",
42+
"🦵",
43+
"🦶",
44+
"🧠",
45+
"🦷",
46+
"👀",
47+
"👅",
48+
"👄",
49+
"🩸",
50+
"🤰",
51+
"🐵",
52+
"🦍",
53+
"🐶",
54+
"🐕",
55+
"🐺",
56+
"🦊",
57+
"🦁",
58+
"🦄",
59+
"🐮",
60+
"🐷",
61+
"🐏",
62+
"🦃",
63+
"🐥",
64+
"🦉",
65+
"🦆",
66+
"🦩",
67+
"😂",
68+
"🌍",
69+
"🚗",
70+
"🗿",
71+
"🌋",
72+
"🗽"
73+
]
74+
75+
console.log("len", ARBITRARY_LIST_OF_EMOJIS.length)
76+
77+
// Dumb af
78+
79+
// Replace 16 with the first 16 digits
80+
// Demo string
81+
// 0x5ac989f52ea4c399343f6c0cf5a4810fc1bdac5773de37ca0cd0a8287f75a5c6
82+
83+
const NIBBLE_LETTERS_TO_NUMBER = {
84+
"a": 10,
85+
"b": 11,
86+
"c": 12,
87+
"d": 13,
88+
"e": 14,
89+
"f": 15
90+
}
91+
92+
function fromNibbleCharToNumber(nibble: string): number {
93+
if(NIBBLE_LETTERS_TO_NUMBER[nibble]) {
94+
return NIBBLE_LETTERS_TO_NUMBER[nibble]
95+
}
96+
97+
return Number(nibble)
98+
}
99+
100+
function fromHexStringToNibbles(hash: string): number[] {
101+
// Check and remove 0x
102+
// Copy then replace
103+
// Copy so we avoid any weirdness
104+
const trimmed = JSON.parse(JSON.stringify(hash)).replace(/^0x/, "")
105+
let converted: string[] = Array.from(trimmed)
106+
107+
return converted.map(nibble => fromNibbleCharToNumber(nibble))
108+
}
109+
110+
111+
112+
function fromNibbleNumberToEmoji(value: number): string {
113+
return ARBITRARY_LIST_OF_EMOJIS[value]
114+
}
115+
116+
export function fromHexStringToEmojis(hash: string): string[] {
117+
const asNibblesNumbers = fromHexStringToNibbles(hash)
118+
return asNibblesNumbers.map(nibble => fromNibbleNumberToEmoji(nibble))
119+
}
120+
export default function fromHexStringToEmojiString(hash: string): string {
121+
const asNibblesNumbers = fromHexStringToNibbles(hash)
122+
return asNibblesNumbers.map(nibble => fromNibbleNumberToEmoji(nibble)).join("")
123+
}
124+
125+
console.log(fromHexStringToNibbles("0x5ac989f52ea4c399343f6c0cf5a4810fc1bdac5773de37ca0cd0a8287f75a5c6"))
126+
console.log(fromHexStringToEmojis("0x5ac989f52ea4c399343f6c0cf5a4810fc1bdac5773de37ca0cd0a8287f75a5c6"))

0 commit comments

Comments
 (0)