Copy
Ask AI
import { SHA256 } from '@tevm/voltaire/SHA256';
import { Hex } from '@tevm/voltaire/Hex';
// Hash a simple string
const message = 'Hello, World!';
const hash = SHA256.hash(new TextEncoder().encode(message));
const hexHash = Hex(hash);
console.log('SHA-256 hash:', hexHash);
// Hash another string
const hash2 = SHA256.hash(new TextEncoder().encode('Tevm'));
const hexHash2 = Hex(hash2);
console.log('Tevm hash:', hexHash2);
// Hash is always 32 bytes (256 bits)
console.log('Hash length:', hash.length, 'bytes');
This is a fully executable example. View the complete source with test assertions at
examples/hashing/sha256-hash.ts.
