Skip to content

ISSUE #101: [Core/Crypto]: Canonical Community Digest SHA-256 Hashing Engine #3

Description

@josealfredo79

🎯 Problem Statement

To create an immutable provenance passport for an indigenous micro-lot (coffee, honey, or backstrap loom textiles), we must compute a deterministic cryptographic digest combining:

  1. Producer identification and parcel location.
  2. The authentic oral audio testimonial in an indigenous variant (Tu'un Savi, Zapotec, or Spanish).
  3. The photograph of the harvested batch or textile sample.
  4. Unix timestamp and geographical coordinates (5-decimal precision).

🛠️ Technical Tasks

  • Refactor CryptoEngine.computeSha256() to accept string, Uint8Array, and ArrayBuffer.
  • Implement canonicalizeLotPayload(input: LotDigestInput): string ensuring dictionary keys are sorted alphabetically before serialization to prevent cross-platform hash discrepancies.
  • Support hybrid execution: Native window.crypto.subtle in browsers with automatic fallback to Node's node:crypto when run server-side or in CI unit tests.
  • Write test suite in src/core/crypto/__tests__/CryptoEngine.test.ts with at least 6 deterministic test vectors.

✅ Definition of Done (Acceptance Criteria)

  • npm run test passes 100% without UI or React dependencies.
  • Calling the digest with identical values in differing key order yields the exact same SHA-256 hash.
  • Zero heavy external dependencies (leverages native Web Crypto API).

  • Target Module: src/core/crypto/CryptoEngine.ts

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions