JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 919
  • Score
    100M100P100Q98983F
  • License Apache-2.0

bigint to buffer conversion with native support and built-in conversion helpers

Package Exports

  • @gsknnft/bigint-buffer
  • @gsknnft/bigint-buffer/conversion

Readme

CI Release

@gsknnft/bigint-buffer

Secure BigInt ⇆ Buffer conversion with native bindings, browser fallbacks, and the bigint-conversion helper APIs built in. This is the actively maintained fork of the original bigint-buffer.

Upgrade notice: Use @gsknnft/bigint-buffer@1.4.3+ for verified bindings, fresh CI, and npm-based workflows across Node 18–24.

NPM Version Node Version


Why This Package

  • Native N-API binding with pure-JS fallback for browsers and constrained environments.
  • Conversion helpers from bigint-conversion in-core (no extra deps).
  • ESM and CJS exports plus a UMD/browser bundle.
  • Actively maintained; legacy bigint-buffer is deprecated and flagged by audits.

Install

npm install @gsknnft/bigint-buffer
# or pnpm/yarn if preferred

Quick Start

import {
  toBigIntBE, toBigIntLE, toBufferBE, toBufferLE,
  bigintToBuf, bufToBigint, bigintToHex, hexToBigint,
  bigintToText, textToBigint, bigintToBase64, base64ToBigint,
} from "@gsknnft/bigint-buffer";

toBigIntBE(Buffer.from("deadbeef", "hex")); // 3735928559n
toBufferLE(0xdeadbeefn, 6);                 // <Buffer ef be ad de 00 00>
bigintToHex(123456789n);                    // "075bcd15"
textToBigint("Hello");                      // 0x48656c6c6f
bigintToBase64(123456789n);                 // "B1vNFQ=="

Conversion Utilities

import { conversionUtils } from "@gsknnft/bigint-buffer";

const arrBuf = conversionUtils.bigintToBuf(123456789n, true); // ArrayBuffer
const hex = conversionUtils.bigintToHex(123456789n, true);    // '0x...' format
const text = conversionUtils.bigintToText(123456789n);

Runtime

  • Native binary: build/Release/bigint_buffer.node (loads automatically when available).
  • Fallback: pure JS bundle for browser and non-native installs.
  • Check which path loaded:
    import { isNative } from "@gsknnft/bigint-buffer";
    console.log(isNative); // true when native binding is active

Commands

npm run build           # bundle + declarations + type check
npm test                # vitest with coverage
npm run test:node       # mocha against built JS (after build/compile)
npm run rebuild:native  # rebuild the N-API binding

API Surface (high level)

  • Core: toBigIntBE/LE, toBufferBE/LE, validateBigIntBuffer, isNative
  • Conversion: bigintToBuf, bufToBigint, bigintToHex, hexToBigint, bigintToText, textToBigint, bigintToBase64, base64ToBigint, bufToHex, hexToBuf, textToBuf, bufToText, parseHex

All helpers are endian-safe and validated across Node and browser builds.


Support