]> git.ardis.lu - 4-byte-gen/commitdiff
Calculate original function name selector
authorArdis Lu <ardisglu@gmail.com>
Thu, 23 Mar 2023 06:44:45 +0000 (23:44 -0700)
committerArdis Lu <ardisglu@gmail.com>
Thu, 23 Mar 2023 06:44:45 +0000 (23:44 -0700)
index.html

index 281628a9b3b6431d29f7f722a76233c3f8d86b09..a41ca89c150f336a2d33a76cd3db1be5efaa7f1b 100644 (file)
   </main>
 
   <script type="module">
+    // From noble-hashes v1.3.0
+    import { keccak256 } from '/keccak256.js';
+    const encoder = new TextEncoder();
+
     /* Globals */
 
     const status = document.querySelector('p.status');
 
         // Add any new functions to the state
         const normalizedName = `${name}(${parametersTypes})`;
+        const byteArray = keccak256(encoder.encode(normalizedName)).slice(0, 4);
+        const hash = `0x${[...byteArray].map(b => b.toString(16).padStart(2, '0')).join('')}`;
         newState.set(normalizedName, {
           name,
           parametersTypes,
           normalizedName,
-          normalizedSelector: null,
+          normalizedSelector: hash,
           optimizedName: null,
           optimizedSelector: null,
           seed: 0,
         row.actionElem = rowElem.insertCell();
 
         row.originalNameElem.textContent = row.normalizedName;
-        row.originalSelectorElem.textContent = row.originalSelector;
+        row.originalSelectorElem.textContent = row.normalizedSelector;
         row.optimizedNameElem.textContent = row.optimizedName;
         row.optimizedSelectorElem.textContent = row.optimizedSelector;
         row.seedElem.textContent = row.seed;
This page took 0.039281 seconds and 4 git commands to generate.