nodejs-keccak256
यह क्या करती है
यह टूल आपके JavaScript और TypeScript कोड में Ethereum के लिए सही 'हैशिंग' तरीका (यह एक ऐसा फ़ंक्शन है जो डेटा को यूनिक अक्षरों के क्रम में बदल देता है) इस्तेमाल करने में मदद करता है। गलत फ़ंक्शन इस्तेमाल करने से ट्रांज़ैक्शन और दूसरे ज़रूरी कामों में एरर आ सकते हैं।
कब इस्तेमाल करें
- ✓जब आप Ethereum के साथ इंटरैक्ट करने वाला कोड लिख रहे हों।
- ✓जब आपको फ़ंक्शन या इवेंट के लिए यूनिक आइडेंटिफ़ायर बनाने हों।
- ✓अगर आपको लगता है कि आपके Ethereum कोड में अनचाहे एरर आ रहे हैं।
Skill का लिंक
https://github.com/affaan-m/ECC/blob/main/skills/nodejs-keccak256/SKILL.mdइसे कॉपी करके अपने AI (Claude, ChatGPT या Cursor) में पेस्ट करें और निर्देशों का पालन करने को कहें।
कैसे इस्तेमाल करें
सबसे आसान तरीका: मैसेज कॉपी करके अपने AI में पेस्ट करें। वह skill पढ़कर निर्देशों का पालन करेगा।
पेस्ट करने के लिए तैयार मैसेज
Claude Code, Codex या Cursor के लिए: प्रोजेक्ट फ़ोल्डर में चलाएँ और skill इंस्टॉल हो जाएगी।
SKILL.md डाउनलोड करें और अपने एजेंट के skills फ़ोल्डर में रखें।
AI से क्या माँगें: उदाहरण
“JavaScript में Ethereum के लिए मैसेज का 'hash' सही तरीके से कैसे निकालूँ, यह कैसे पक्का करूँ?”
हर हफ़्ते 5 नई skills, 1 मिनट में पढ़ें।
यह कैसे काम करती है
यह Node.js के डिफ़ॉल्ट हैशिंग फ़ंक्शन को बदल देता है, जो Ethereum से अलग होता है, और उसकी जगह सही Keccak-256 स्टैंडर्ड वाला फ़ंक्शन लगाता है। इससे आपका कोड बिना बताए गलत नतीजे नहीं देगा।
तकनीकी सामग्री (मूल SKILL.md)
लेखक का मूल टेक्स्ट, अंग्रेज़ी में, सीधे GitHub से।
Node.js Keccak-256
Ethereum uses Keccak-256, not the NIST-standardized SHA3 variant exposed by Node's crypto.createHash('sha3-256').
When to Use
- Computing Ethereum function selectors or event topics
- Building EIP-712, signature, Merkle, or storage-slot helpers in JS/TS
- Reviewing any code that hashes Ethereum data with Node crypto directly
How It Works
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
Examples
ethers v6
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],
);
viem
import { keccak256, toBytes } from 'viem';
const hash = keccak256(toBytes('hello'));
web3.js
const hash = web3.utils.keccak256('hello');
const packed = web3.utils.soliditySha3(
{ type: 'address', value: '0x742d35Cc6634C0532925a3b8D4C9B569890FaC1c' },
{ type: 'uint256', value: '100' },
);
Common patterns
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]),
);
}
Address from public key
import { keccak256 } from 'ethers';
function pubkeyToAddress(pubkeyBytes: Uint8Array): string {
const hash = keccak256(pubkeyBytes.slice(1));
return '0x' + hash.slice(-40);
}
Audit your codebase
grep -rn "createHash.*sha3" --include="*.ts" --include="*.js" --exclude-dir=node_modules .
grep -rn "keccak256" --include="*.ts" --include="*.js" . | grep -v node_modules
Rule
For Ethereum contexts, never use crypto.createHash('sha3-256'). Use Keccak-aware helpers from ethers, viem, web3, or another explicit Keccak implementation.
अक्सर पूछे जाने वाले सवाल
Node.js का hash Ethereum के Keccak-256 से अलग क्यों है?
Node.js SHA3 नाम का स्टैंडर्ड इस्तेमाल करता है, जबकि Ethereum थोड़ा अलग स्टैंडर्ड Keccak-256 इस्तेमाल करता है। दिखने में ये मिलते-जुलते हैं, लेकिन एक ही डेटा पर अलग नतीजे देते हैं।
अगर मैं गलत hash इस्तेमाल करूँ तो क्या होगा?
Ethereum नेटवर्क के साथ काम करते समय आपका कोड फ़ेल हो सकता है, जैसे ट्रांज़ैक्शन भेजने, मैसेज साइन करने या डेटा वेरिफ़ाई करने में। इससे ऐसे एरर आ सकते हैं जिनकी वजह ढूँढना मुश्किल हो।
क्या मुझे Keccak-256 अंदर से कैसे काम करता है, यह समझना होगा?
नहीं, इसकी तकनीकी बारीकियाँ समझना ज़रूरी नहीं है। यह टूल वह काम संभाल लेता है, ताकि आप बिना उलझन के सही फ़ंक्शन इस्तेमाल कर सकें।
जानकारी
लेखक का मूल विवरण
Prevent Ethereum hashing bugs in JavaScript and TypeScript. Node's sha3-256 is NIST SHA3, not Ethereum Keccak-256, and silently breaks selectors, signatures, storage slots, and address derivation. Use when hashing for Ethereum in JavaScript or TypeScript, or when a selector, signature, storage slot, or derived address is wrong.
repo: affaan-m/ECC
लोकप्रियता
- GitHub स्टार
- 280k
- रैंकिंग में स्थान
- #367
- लाइसेंस
- MIT
- अपडेट की गई
- 15/10/2026
कमेंट
- …
इस repository की और skills
accessibility
280kयह आपके एजेंट को ऐसे इंटरफ़ेस बनाने में मदद करता है जिन्हें हर कोई इस्तेमाल कर सके। यह पक्का करता है कि वेबसाइट और ऐप दिव्यांग लोगों के लिए भी अच्छे से काम करें, जैसे नेत्रहीन या जिन्हें चलने-फिरने में दिक्कत होती है।
agent-architecture-audit
280kयह आपके एजेंट को जाँचने देता है कि सब कुछ सही से चल रहा है। यह AI सिस्टम में समस्याएँ ढूँढकर ठीक करता है, ताकि वे उम्मीद के मुताबिक काम करें।
agent-eval
280kयह आपके एजेंट को अलग-अलग AI coding tools की तुलना करने में मदद करता है। यह मापता है कि किसी खास काम के लिए कौन सा टूल ज़्यादा तेज़, सस्ता और भरोसेमंद है।
agent-harness-construction
280kयह आपके एजेंट को काम कैसे करना है, यह बेहतर समझने में मदद करता है। यह उन tools और instructions को बेहतर बनाता है जिनका एजेंट इस्तेमाल करता है, ताकि उसकी सफलता की संभावना बढ़े।
मिलती-जुलती skills
diffs
394kयह आपके एजेंट को बदलावों का असली diff बनाने देती है, जिसे व्यूअर लिंक या इमेज फ़ाइल के रूप में साझा किया जा सकता है, हाथ से लिखे सारांश के बजाय।
coding-agent
394kयह आपके एजेंट को बड़े कोडिंग काम Codex, Claude Code या OpenCode को बैकग्राउंड वर्कर के रूप में सौंपने, फिर उसकी प्रगति जांचने में मदद करती है।
gh-issues
394kयह आपके एजेंट को GitHub issues खोजने, उनमें से काम करने लायक चुनने, और सुधार के साथ pull requests खोलने में मदद करती है, जिसमें समीक्षा टिप्पणियों का फ़ॉलो-अप भी शामिल है।