Something went wrong. Try again.
A local-first note taking app
Something went wrong. Try again.
TypeScript
12345678910111213141516171819202122232425262728293031323334353637383940414243import { describe, expect, it } from 'vitest';
import { contentHash, isContentEqual } from './content';
describe('contentHash', () => { // Known SHA-256 vectors (FIPS 180-4) — verify the hashing produces correct, // stable output (matches `crypto.createHash('sha256')`). it('matches standard SHA-256 test vectors', () => { expect(contentHash('')).toBe( 'sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855', ); expect(contentHash('abc')).toBe( 'sha256:ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad', ); });
it('hashes a multi-block message (> 64 bytes)', () => { const msg = 'abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq'; // 56 bytes expect(contentHash(msg)).toBe( 'sha256:248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1', ); });
it('hashes Uint8Array and matches the equivalent UTF-8 string', () => { expect(contentHash(new TextEncoder().encode('abc'))).toBe( contentHash('abc'), ); });});
describe('isContentEqual', () => { it('compares strings and byte arrays', () => { expect(isContentEqual('a', 'a')).toBe(true); expect(isContentEqual('a', 'b')).toBe(false); expect(isContentEqual(new Uint8Array([1, 2]), new Uint8Array([1, 2]))).toBe( true, ); expect(isContentEqual(new Uint8Array([1]), new Uint8Array([1, 2]))).toBe( false, ); });});