AWS SDK JS Crypto Helpers (SHA256 Browser)

Isomorphic SHA-256 hashing for the browser, preferring native WebCrypto with a pure-JS fallback for full compatibility.

Library
npm
v5.2.0
69 stars
Apache License 2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
45 /100 Fair
Development Activity 52
Maintenance 8
Community 48
Maturity 60
Momentum 12

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
66 /100 Good
Architecture 78
Code Quality 82
Innovation 45
Learning Curve 60

@aws-crypto/sha256-browser is the browser-targeted SHA-256 implementation from AWS’s aws-sdk-js-crypto-helpers monorepo, the small collection of cryptographic primitive packages (@aws-crypto/*) that AWS SDK for JavaScript v3 uses internally for request signing (SigV4) and payload integrity checksums. Rather than hand-writing a hash routine, it exposes a single Sha256 class that checks for window.crypto.subtle support at construction time and transparently delegates to the native Web Crypto API when present, falling back to the pure-JavaScript implementation from the sibling @aws-crypto/sha256-js package when it isn’t — giving callers one consistent update/digest/reset interface regardless of runtime.

Because it backs the official AWS SDK’s signing and checksum paths, it’s built to the same reliability bar: typed against a shared Checksum interface, unit-tested with mocha/chai/sinon against stubbed WebCrypto calls, and published under Apache-2.0 alongside its sibling sha256-js, sha256-universal, and supports-web-crypto packages.

What You Get

  • A single Sha256 class implementing update(), digest(), and reset() against a shared Checksum interface
  • Automatic runtime feature detection via @aws-crypto/supports-web-crypto, with zero configuration needed
  • A pure-JS fallback (@aws-crypto/sha256-js) for environments without window.crypto.subtle
  • Both plain hashing and HMAC-with-secret modes through the same constructor signature
  • Dual CJS/ESM builds (build/main, build/module) with TypeScript type declarations

Common Use Cases

  • Computing SigV4 request-signing hashes inside AWS SDK for JavaScript v3 clients running in the browser
  • Verifying S3 payload/content integrity checksums client-side before or after upload
  • Hashing user input or file contents in a web app without shipping a heavier general-purpose crypto library
  • Generating HMAC digests for lightweight browser-side request authentication

Under The Hood

Architecture

The package is part of a lerna/npm-workspaces monorepo that exposes a single class, Sha256 (packages/sha256-browser/src/crossPlatformSha256.ts), implementing a shared Checksum interface (update, digest, reset). At construction it calls supportsWebCrypto(locateWindow()) to decide whether to delegate to WebCryptoSha256 (using crypto.subtle.digest/sign/importKey) or fall back to the pure-JS Sha256 from the sibling sha256-js package. It’s a clean strategy/adapter pattern: one thin dispatcher class picks between two interchangeable backends at runtime, both satisfying the same contract, with buffer conversion centralized in a shared util package. Because AWS SDK v3’s signing and checksum code across many clients depends on this exact interface, it functions as a load-bearing shared abstraction rather than a private implementation detail.

Tech Stack

Written in TypeScript and compiled twice (tsc) to CJS and ESM outputs with dual package.json exports, managed inside an npm-workspaces plus Lerna monorepo. Sibling workspace dependencies are linked via the file: protocol during development, with pinned semver ranges for external AWS SDK type and utility packages. There’s no runtime framework — it’s a leaf utility package. Testing uses mocha, chai, sinon, and ts-node; releases run through both GitHub Actions and internal AWS CodeBuild pipelines, with a local Verdaccio registry used to dry-run publishes.

Code Quality

Tests exist and are meaningful, stubbing crypto.subtle and asserting exact call arguments for both plain digests and HMAC key imports. Error handling is deliberate but minimal — an explicit catch on the key-import promise avoids unhandled-rejection noise while still surfacing errors through the real digest() call. Types are used consistently via shared interfaces, and the test suite itself is type-checked before running. Prettier plus husky/lint-staged enforce formatting on commit, and CI runs on both GitHub Actions and CodeBuild.

What Makes It Unique

SHA-256 itself is a standard, well-known algorithm, so the genuinely useful technical choice here is the “prefer native WebCrypto, fall back to pure JS” dispatch hidden behind one stable class name — letting the rest of the AWS SDK v3 ecosystem call a single consistent async hashing API without every caller needing to feature-detect window.crypto.subtle itself. The public API is minimal and requires almost no boilerplate to adopt, though it isn’t something an experienced developer couldn’t reasonably build from scratch.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers