Use the correct Ethereum Keccak-256 hashing in Node.js and TypeScript.
Copy the install command and let the AI configure it · recommended for beginners
Please install the "nodejs-keccak256" skill from askskill: 1. Download https://raw.githubusercontent.com/affaan-m/ECC/main/skills/nodejs-keccak256/SKILL.md 2. Save it as ~/.claude/skills/nodejs-keccak256/SKILL.md 3. Reload skills and tell me it's ready
Please review this Node.js/TypeScript code for cases where Ethereum Keccak-256 was mistakenly implemented using Node's built-in sha3-256. Explain the risks and provide the correct replacement with sample code.
Identifies the wrong hash usage, explains impacts on selectors and signatures, and provides correct replacement code.
I need to compute a Solidity function signature's 4-byte selector in JavaScript. Please use Ethereum Keccak-256 instead of NIST SHA3, provide a complete example, and show how to derive the selector from the signature string.
Provides runnable code to compute the selector correctly and clearly explains why sha3-256 should not be used.
Help me debug inconsistencies in address derivation, event topic generation, or storage slot calculation in this script. Focus on whether sha3-256 and Keccak-256 were mixed up, and provide fixes, test cases, and cautions.
Returns the root cause, corrected hashing approach, and test suggestions for regression validation.
Ethereum uses Keccak-256, not the NIST-standardized SHA3 variant exposed by Node's crypto.createHash('sha3-256').
The two algorithms produce different outputs for the same input, and Node will not warn you.
import crypto from 'crypto';
import { keccak256, toUtf8Bytes } from 'ethers';
const data = 'hello';
const nistSha3 = crypto.createHash('sha3-256').update(data).digest('hex');
const keccak = keccak256(toUtf8Bytes(data)).slice(2);
console.log(nistSha3 === keccak); // false
import { keccak256, toUtf8Bytes, solidityPackedKeccak256, id } from 'ethers';
const hash = keccak256(new Uint8Array([0x01, 0x02]));
const hash2 = keccak256(toUtf8Bytes('hello'));
const topic = id('Transfer(address,address,uint256)');
const packed = solidityPackedKeccak256(
['address', 'uint256'],
['0x742d35Cc6634C0532925a3b8D4C9B569890FaC1c', 100n],
);
import { keccak256, toBytes } from 'viem';
const hash = keccak256(toBytes('hello'));
const hash = web3.utils.keccak256('hello');
const packed = web3.utils.soliditySha3(
{ type: 'address', value: '0x742d35Cc6634C0532925a3b8D4C9B569890FaC1c' },
{ type: 'uint256', value: '100' },
);
import { id, keccak256, AbiCoder } from 'ethers';
const selector = id('transfer(address,uint256)').slice(0, 10);
const typeHash = keccak256(toUtf8Bytes('Transfer(address from,address to,uint256 value)'));
function getMappingSlot(key: string, mappingSlot: number): string {
return keccak256(
AbiCoder.defaultAbiCoder().encode(['address', 'uint256'], [key, mappingSlot]),
);
}
import { keccak256 } from 'ethers';
function pubkeyToAddress(pubkeyBytes: Uint8Array): string {
const hash = keccak256(pubkeyBytes.slice(1));
return '0x' + hash.slice(-40);
}
grep -rn "createHash.*sha3" --include="*.ts" --include="*.js" --exclude-dir=node_modules .
grep -rn "keccak256" --include="*.ts" --include="*.js" . | grep -v node_modules
For Ethereum contexts, never use crypto.createHash('sha3-256'). Use Keccak-aware helpers from ethers, viem, web3, or another explicit Keccak implementation.
Audit Claude skills and commands with quick scans or full stocktakes.
Create iOS liquid glass interfaces with dynamic visuals and interactive morphing.
Record polished web app UI demo videos for walkthroughs, tutorials, and showcases.
Plan demand forecasts, safety stock, and replenishment for multi-location retail inventory.
Unify multi-channel notifications for routing, deduplication, escalation, and inbox consolidation.
Audit, plan, and implement SEO improvements for better search visibility.
Compute and verify Keccak cryptographic hashes for data integrity checks.
Compute hashes, convert encodings, decode JWTs, and generate UUIDs quickly.
Retrieve exact multi-chain protocol specs and canonical contract addresses with natural language.
Compute cryptographic hashes and HMACs for integrity checks and verification.