Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:0xsline OpenChatCut NormalizeSha256Hash

From Leeroopedia
Knowledge Sources
Domains Hashing, Validation, Media_Import
Last Updated 2026-10-22 14:00 GMT

Overview

Concrete pure function that validates a value is a complete 64-character SHA-256 hex digest and returns its canonical lowercase form, or `undefined` if invalid.

Description

The normalizeSha256Hash function is a pure, total validator:

  • Accepts any `unknown` value.
  • Validates the value is a string matching the regex `/^[0-9a-fA-F]{64}$/` (exactly 64 hex characters).
  • Returns the lowercase form if valid.
  • Returns `undefined` if the value is not a string, is the wrong length, or contains non-hex characters.

This is used to normalize and validate hashes from various sources (file hashing, user input, stored values) before persisting them.

Usage

  • Media import: Called by `importLocalMedia` to normalize the raw `sha256File` output.
  • Hash validation: Used anywhere a SHA-256 hash is received from untrusted input.

Code Reference

Source Location

  • Repository: OpenChatCut
  • File:*** shared/content-hash.ts

Signature

export function normalizeSha256Hash(value: unknown): string | undefined;

Import

import { normalizeSha256Hash } from '../shared/content-hash.ts';

I/O Contract

Inputs

Name Type Required Description
value unknown Yes Value to validate as a SHA-256 hash

Outputs

Name Type Description
returns undefined Lowercase 64-char hex digest, or undefined if invalid

Usage Examples

Validate and Normalize

import { normalizeSha256Hash } from '../shared/content-hash.ts';

const valid = normalizeSha256Hash('A1B2C3D4E5F6' /* ...64 chars */);
console.log(valid); // "a1b2c3d4e5f6..." (lowercased)

const invalid = normalizeSha256Hash('not-a-hash');
console.log(invalid); // undefined

const fromNumber = normalizeSha256Hash(42);
console.log(fromNumber); // undefined

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment