Skip to content

Project Overhaul - #47

Merged
andyperlitch merged 4 commits into
masterfrom
project-overhaul
Aug 27, 2026
Merged

andyperlitch merged 4 commits into
masterfrom
project-overhaul

Conversation

@andyperlitch

Copy link
Copy Markdown
Owner

Summary

Port jsbn to TypeScript and ship it as a dual CJS + ESM package (plus an IIFE browser bundle) with bundled .d.ts files, so consumers can drop @types/jsbn. The public and protected APIs stay compatible with existing callers (including node-forge).

Fix long-standing runtime bugs along the way: always use the 28-bit am3 multiply kernel (no user-agent sniffing — this was breaking Node 21+ navigator and React Native), use a platform CSPRNG in SecureRandom.nextBytes when one exists, and reduce negative values in modInverse instead of hanging.

Add a GitHub Pages demo/benchmark (jsbn vs bn.js, big-integer, and bignumber.js) with a native-BigInt fast path, plus CI, npm publish, and Pages deploy workflows.

What’s in this branch

Four commits on top of origin/master:

  • Address open PRs and issues, update project structure — TypeScript source in src/, Vitest tests, tsup dual/IIFE builds, rewritten README + CHANGELOG, SECURITY.md, CI and release workflows. Version bump to 1.3.0. engines.node is >=18.
  • Demo page with perf tests — docs/ playground and in-browser benchmark; native BigInt path for arithmetic; Pages deploy workflow.
  • Updated demo with node run — richer demo UI (tabs, more ops).
  • Fixed workflow — drop the github-pages environment block from the Pages workflow so deploy can run without that environment being configured.

Compatibility notes

  • Named exports: import { BigInteger, SecureRandom } from 'jsbn'
  • Default export still works: import BigInteger from 'jsbn'
  • CJS: require('jsbn').BigInteger
  • Protected prototype methods (copyTo, fromString, am, Barrett, limb fields, etc.) remain for dependents
  • Arithmetic still takes BigInteger arguments, not JS numbers
  • Publish contents are dist/ + changelog/security docs (no raw index.js at the package root)

Test plan

  • npm ci && npm run typecheck && npm test && npm run build
  • CJS smoke: require('./dist/index.cjs').BigInteger add 10 + 32 === 42
  • ESM smoke: import { BigInteger } from './dist/index.js' same check
  • Confirm modInverse on a negative value (-3 mod 2) returns 1 and does not hang
  • Confirm SecureRandom.nextBytes fills a buffer without throwing in Node
  • Open the demo (docs/index.html after npm run pages:build) — run a few arithmetic ops and the benchmark suite
  • After merge: Pages workflow deploys to https://andyperlitch.github.io/jsbn/
  • Tag v1.3.0 to exercise the npm publish + GitHub Release workflow (needs NPM_TOKEN)

@andyperlitch
andyperlitch merged commit 0c5810e into master Aug 27, 2026
3 checks passed
@andyperlitch andyperlitch mentioned this pull request Aug 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant