import { SHA256, enc } from '../sha_256' describe('SHA256', () => { it('computes correct hash for empty string', () => { const hash = SHA256('').toString(enc.Hex) expect(hash).toBe('e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855') }) it('computes correct hash for "abc"', () => { const hash = SHA256('abc').toString(enc.Hex) expect(hash).toBe('ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad') }) it('computes correct hash for "The quick brown fox jumps over the lazy dog"', () => { const hash = SHA256('The quick brown fox jumps over the lazy dog').toString(enc.Hex) expect(hash).toBe('d7a8fbb307d7809469ca9abcb0082e4f8d5651e46d3cdb762d02d0bf37c9e592') }) it('computes correct hash for longer message', () => { const message = 'abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq' const hash = SHA256(message).toString(enc.Hex) expect(hash).toBe('248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1') }) it('computes correct hash for message with 1 million "a" characters', () => { const message = 'a'.repeat(1000000) const hash = SHA256(message).toString(enc.Hex) expect(hash).toBe('cdc76e5c9914fb9281a1c7e284d73e67f1809a48a497200e046d39ccc7112cd0') }) it('computes correct hash for UTF-8 string with emoji', () => { const hash = SHA256('Hello 👋 World 🌍').toString(enc.Hex) // This is the expected SHA-256 hash for this UTF-8 encoded string expect(hash).toBe('c15ee319b97bfd23fa98590baf0b47d1f7b7b81f9e5bf99d8275867e2e4a32a2') }) it('computes correct hash for JSON payload', () => { const payload = JSON.stringify({ events: [{ name: 'test', meta: { foo: 'bar' } }] }) const hash = SHA256(payload).toString(enc.Hex) expect(hash).toBe('5e4043aadad336890b9795ee03675a9de1a6abbc4e84f9f95daaffb21569312e') }) it('toString without encoding parameter defaults to hex', () => { const hash = SHA256('abc').toString() expect(hash).toBe('ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad') }) it('produces consistent results for the same input', () => { const input = 'test message' const hash1 = SHA256(input).toString(enc.Hex) const hash2 = SHA256(input).toString(enc.Hex) expect(hash1).toBe(hash2) }) it('produces different hashes for different inputs', () => { const hash1 = SHA256('message 1').toString(enc.Hex) const hash2 = SHA256('message 2').toString(enc.Hex) expect(hash1).not.toBe(hash2) }) it('handles strings with special characters', () => { const hash = SHA256('!@#$%^&*()_+-=[]{}|;:",.<>?/~`').toString(enc.Hex) expect(hash).toBe('67764597efaadfd3a9d89032105c9fcde16c6f05d16214e42488af193abb280a') }) it('handles strings with newlines and tabs', () => { const hash = SHA256('line1\nline2\tline3').toString(enc.Hex) expect(hash).toBe('450c0302bb6c2b9d81f81c8c868f7e96e3a35bc83751a08b7da09e77c4f13eec') }) })