@gsknnft/bigint-buffer 1.2.0 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +76 -17
- package/dist/index.cjs +90 -0
- package/package.json +100 -98
- package/rollup.cjs.config.js +8 -0
- /package/{rollup.config.js → rollup.esm.config.js} +0 -0
package/README.md
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
# 💪🔢 bigint-buffer: Buffer Utilities for TC39 BigInt Proposal
|
|
2
|
-
[](https://www.npmjs.org/package/bigint-buffer)
|
|
3
|
-
[](https://travis-ci.com/no2chem/bigint-buffer)
|
|
4
|
-
[](https://coveralls.io/r/no2chem/bigint-buffer)
|
|
5
|
-

|
|
6
|
-
[](https://github.com/sigilnet/bigintbuffer)
|
|
1
|
+
# 💪🔢 @gsknnft/bigint-buffer: Secure Buffer Utilities for TC39 BigInt Proposal
|
|
7
2
|
|
|
8
|
-
[
|
|
3
|
+
[](https://www.npmjs.com/package/@gsknnft/bigint-buffer)
|
|
4
|
+
[](https://nodejs.org)
|
|
5
|
+
[](https://github.com/gsknnft/bigintbuffer)
|
|
9
6
|
|
|
10
7
|
---
|
|
11
8
|
|
|
@@ -13,24 +10,84 @@
|
|
|
13
10
|
|
|
14
11
|
As of October 2025, `bigint-buffer@1.1.5` is **compromised and flagged by multiple audit tools** due to unresolved vulnerabilities in its native bindings and transitive dependencies. No upstream patch has been published.
|
|
15
12
|
|
|
16
|
-
This fork — `@
|
|
13
|
+
This fork — `@gsknnft/bigint-buffer@1.2.0` — is a **sovereign override**:
|
|
17
14
|
- ✅ Rebuilt with modern TypeScript and Rollup
|
|
18
15
|
- ✅ Native bindings patched and rebuilt via `node-gyp`
|
|
19
16
|
- ✅ Browser fallback formalized via `"browser"` field
|
|
20
17
|
- ✅ ESM/CJS duality declared via `"exports"`
|
|
21
18
|
- ✅ Peer dependency alignment and audit compliance restored
|
|
22
19
|
|
|
23
|
-
If you're using `bigint-buffer` in a secure or reproducible system, **migrate to `@
|
|
20
|
+
If you're using `bigint-buffer` in a secure or reproducible system, **migrate to `@gsknnft/bigint-buffer`** or override via `pnpm`:
|
|
24
21
|
|
|
25
22
|
```json
|
|
26
23
|
"pnpm": {
|
|
27
24
|
"overrides": {
|
|
28
|
-
"bigint-buffer": "
|
|
25
|
+
"bigint-buffer": "@gsknnft/bigint-buffer@1.2.0"
|
|
29
26
|
}
|
|
30
27
|
}
|
|
31
28
|
```
|
|
29
|
+
## 🔍 Differences from Upstream
|
|
32
30
|
|
|
33
|
-
|
|
31
|
+
- Rebuilt native bindings with modern Node compatibility
|
|
32
|
+
- Scoped under `@gsknnft` for audit clarity
|
|
33
|
+
- Uses `cpy-cli` instead of deprecated `cpx`
|
|
34
|
+
- Rollup-based bundling for ESM/CJS duality
|
|
35
|
+
- Peer dependency alignment and reproducibility guarantees
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
**This fork is maintained by CoreFlame/GSKNNFT as part of the SigilNet ecosystem.**
|
|
40
|
+
It is the only currently known secure, reproducible implementation of BigInt ↔ Buffer conversion with native fallback.
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
### 🚀 Conversion Utilities (Built-In)
|
|
45
|
+
|
|
46
|
+
`@gsknnft/bigint-buffer` includes direct conversion tools — no need to install `bigint-conversion` separately.
|
|
47
|
+
|
|
48
|
+
>You no longer need `bigint-conversion` as a separate dependency.
|
|
49
|
+
|
|
50
|
+
#### Importing
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
import {
|
|
54
|
+
bigintToBuf,
|
|
55
|
+
bufToBigint,
|
|
56
|
+
bigintToHex,
|
|
57
|
+
hexToBigint,
|
|
58
|
+
bigintToText,
|
|
59
|
+
textToBigint,
|
|
60
|
+
bigintToBase64,
|
|
61
|
+
base64ToBigint
|
|
62
|
+
} from '@gsknnft/bigint-buffer';
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
#### Examples
|
|
66
|
+
|
|
67
|
+
```ts
|
|
68
|
+
const hex = bigintToHex(123456789n); // → "075bcd15"
|
|
69
|
+
const buf = bigintToBuf(123456789n); // → <Buffer 07 5b cd 15>
|
|
70
|
+
const text = bigintToText(123456789n); // → "123456789"
|
|
71
|
+
const base64 = bigintToBase64(123456789n); // → "B1vNFQ=="
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
> All conversions are endian-safe, round-trip validated, and available in both Node and browser environments.
|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
### 🧠 Why This Matters
|
|
79
|
+
|
|
80
|
+
- ✅ No audit vulnerabilities
|
|
81
|
+
- ✅ Native bindings preserved
|
|
82
|
+
- ✅ Conversion logic fused directly into the core
|
|
83
|
+
- ✅ Unified types and exports
|
|
84
|
+
- ✅ No need for `bigint-conversion` or external wrappers
|
|
85
|
+
|
|
86
|
+
---
|
|
87
|
+
|
|
88
|
+
The original introduced utilities for converting TC39 BigInts to and from buffers. This fork builds on that foundation with modern tooling, patched bindings, and reproducible builds.
|
|
89
|
+
|
|
90
|
+
This utility is necessary because BigInts, as proposed, do not support direct conversion between Buffers (or UInt8Arrays), but rather require conversion from buffers to hexadecimal strings then to BigInts, which is suboptimal. This utility includes N-API bindings, so under node, conversion is performed without generating a hexadecimal string. In the browser, normal string conversion is used.
|
|
34
91
|
|
|
35
92
|
---
|
|
36
93
|
|
|
@@ -89,7 +146,7 @@ bigint from hex string from buffer (huge): 1230607±1.02% ops/s 812.61±40.013 n
|
|
|
89
146
|
|
|
90
147
|
bigint-buffer introduces four functions for conversion between buffers and bigints. A small example follows:
|
|
91
148
|
```typescript
|
|
92
|
-
import {toBigIntBE, toBigIntLE, toBufferBE, toBufferLE} from 'bigint-buffer';
|
|
149
|
+
import {toBigIntBE, toBigIntLE, toBufferBE, toBufferLE} from '@gsknnft/bigint-buffer';
|
|
93
150
|
|
|
94
151
|
// Get a big endian buffer of the given width
|
|
95
152
|
toBufferBE(0xdeadbeefn, 8);
|
|
@@ -125,8 +182,6 @@ BE bigint to hex string to buffer (large): 1714292±1.35% ops/s 583.33±37.995 n
|
|
|
125
182
|
BE bigint-buffer to buffer (large, truncated): 5977218±4.68% ops/s 167.30±37.284 ns/op (87 runs)
|
|
126
183
|
```
|
|
127
184
|
|
|
128
|
-
You can run the benchmarks by running `npm run benchmark`.
|
|
129
|
-
|
|
130
185
|
# Typescript Support
|
|
131
186
|
|
|
132
187
|
bigint-buffer supplies typescript bindings, but BigInts are still not supported in typescript, though
|
|
@@ -137,13 +192,17 @@ a pull request has been opened, so support should be coming soon. If you are usi
|
|
|
137
192
|
|
|
138
193
|
Add bigint-buffer to your project with:
|
|
139
194
|
|
|
140
|
-
> `
|
|
195
|
+
> `pnpm add @gsknnft/bigint-buffer`
|
|
196
|
+
|
|
197
|
+
or
|
|
198
|
+
|
|
199
|
+
> `npm install @gsknnft/bigint-buffer`
|
|
141
200
|
|
|
142
201
|
# Documentation
|
|
143
202
|
|
|
144
|
-
Basic API documentation can be found [here](https://
|
|
203
|
+
Basic API documentation can be found [here](https://gsknnft.github.io/bigint-buffer/). Note that v1.0.0 changes
|
|
145
204
|
the name of the original functions to meet style guidelines.
|
|
146
205
|
|
|
147
206
|
# Benchmarks
|
|
148
207
|
|
|
149
|
-
Benchmarks can be run by executing `
|
|
208
|
+
Benchmarks can be run by executing `pnpm run benchmark` from the package directory.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.isNative = void 0;
|
|
5
|
+
exports.toBigIntLE = toBigIntLE;
|
|
6
|
+
exports.validateBigIntBuffer = validateBigIntBuffer;
|
|
7
|
+
exports.toBigIntBE = toBigIntBE;
|
|
8
|
+
exports.toBufferLE = toBufferLE;
|
|
9
|
+
exports.toBufferBE = toBufferBE;
|
|
10
|
+
let converter;
|
|
11
|
+
exports.isNative = false;
|
|
12
|
+
if (!process.browser) {
|
|
13
|
+
try {
|
|
14
|
+
converter = require('bindings')('bigint_buffer');
|
|
15
|
+
exports.isNative = !process.browser && converter !== undefined;
|
|
16
|
+
}
|
|
17
|
+
catch (e) {
|
|
18
|
+
console.warn('bigint: Failed to load bindings, pure JS will be used (try npm run rebuild?)');
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Convert a little-endian buffer into a BigInt.
|
|
23
|
+
* @param buf The little-endian buffer to convert
|
|
24
|
+
* @returns A BigInt with the little-endian representation of buf.
|
|
25
|
+
*/
|
|
26
|
+
function toBigIntLE(buf) {
|
|
27
|
+
if (process.browser || converter === undefined) {
|
|
28
|
+
const reversed = Buffer.from(buf);
|
|
29
|
+
reversed.reverse();
|
|
30
|
+
const hex = reversed.toString('hex');
|
|
31
|
+
if (hex.length === 0) {
|
|
32
|
+
return BigInt(0);
|
|
33
|
+
}
|
|
34
|
+
return BigInt(`0x${hex}`);
|
|
35
|
+
}
|
|
36
|
+
return converter.toBigInt(buf, false);
|
|
37
|
+
}
|
|
38
|
+
function validateBigIntBuffer() {
|
|
39
|
+
try {
|
|
40
|
+
const test = toBigIntLE(Buffer.from([0x01, 0x00]));
|
|
41
|
+
return test === BigInt(1);
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Convert a big-endian buffer into a BigInt
|
|
49
|
+
* @param buf The big-endian buffer to convert.
|
|
50
|
+
* @returns A BigInt with the big-endian representation of buf.
|
|
51
|
+
*/
|
|
52
|
+
function toBigIntBE(buf) {
|
|
53
|
+
if (process.browser || converter === undefined) {
|
|
54
|
+
const hex = buf.toString('hex');
|
|
55
|
+
if (hex.length === 0) {
|
|
56
|
+
return BigInt(0);
|
|
57
|
+
}
|
|
58
|
+
return BigInt(`0x${hex}`);
|
|
59
|
+
}
|
|
60
|
+
return converter.toBigInt(buf, true);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Convert a BigInt to a little-endian buffer.
|
|
64
|
+
* @param num The BigInt to convert.
|
|
65
|
+
* @param width The number of bytes that the resulting buffer should be.
|
|
66
|
+
* @returns A little-endian buffer representation of num.
|
|
67
|
+
*/
|
|
68
|
+
function toBufferLE(num, width) {
|
|
69
|
+
if (process.browser || converter === undefined) {
|
|
70
|
+
const hex = num.toString(16);
|
|
71
|
+
const buffer = Buffer.from(hex.padStart(width * 2, '0').slice(0, width * 2), 'hex');
|
|
72
|
+
buffer.reverse();
|
|
73
|
+
return buffer;
|
|
74
|
+
}
|
|
75
|
+
// Allocation is done here, since it is slower using napi in C
|
|
76
|
+
return converter.fromBigInt(num, Buffer.allocUnsafe(width), false);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Convert a BigInt to a big-endian buffer.
|
|
80
|
+
* @param num The BigInt to convert.
|
|
81
|
+
* @param width The number of bytes that the resulting buffer should be.
|
|
82
|
+
* @returns A big-endian buffer representation of num.
|
|
83
|
+
*/
|
|
84
|
+
function toBufferBE(num, width) {
|
|
85
|
+
if (process.browser || converter === undefined) {
|
|
86
|
+
const hex = num.toString(16);
|
|
87
|
+
return Buffer.from(hex.padStart(width * 2, '0').slice(0, width * 2), 'hex');
|
|
88
|
+
}
|
|
89
|
+
return converter.fromBigInt(num, Buffer.allocUnsafe(width), true);
|
|
90
|
+
}
|
package/package.json
CHANGED
|
@@ -1,98 +1,100 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@gsknnft/bigint-buffer",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "bigint to buffer conversion with native support",
|
|
5
|
-
"main": "dist/index.js",
|
|
6
|
-
"type": "module",
|
|
7
|
-
"browser": {
|
|
8
|
-
"./dist/node.js": "./dist/browser.js"
|
|
9
|
-
},
|
|
10
|
-
"types": "dist/index.d.ts",
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
"
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
"
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
"
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
"
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
"
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
"
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
"
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
"
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
"
|
|
77
|
-
"
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
"
|
|
81
|
-
"
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
"
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
"
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
"
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@gsknnft/bigint-buffer",
|
|
3
|
+
"version": "1.3.1",
|
|
4
|
+
"description": "bigint to buffer conversion with native support",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"browser": {
|
|
8
|
+
"./dist/node.js": "./dist/browser.js"
|
|
9
|
+
},
|
|
10
|
+
"types": "dist/index.d.ts",
|
|
11
|
+
"scripts": {
|
|
12
|
+
"test": "npm run test:node && npm run test:browser",
|
|
13
|
+
"coverage": "istanbul cover ./test/index.js",
|
|
14
|
+
"coveralls": "npm run coverage && coveralls <coverage/lcov.info",
|
|
15
|
+
"lint": "gts check",
|
|
16
|
+
"install": "npm run rebuild || echo \"Couldn't build bindings. Non-native version used.\"",
|
|
17
|
+
"prepare": "npm run compile",
|
|
18
|
+
"prepublishOnly": "rm -rf build/Release; rm build/Makefile; rm build/gyp-*; rm build/*.mk; rm build/*.Makefile; rm *.tgz",
|
|
19
|
+
"test:browser": "karma start karma.conf.js",
|
|
20
|
+
"test:node": "mocha -r ts-node/register src/**/*.spec.ts --timeout 40000",
|
|
21
|
+
"benchmark": "node -r ts-node/register src/index.bench.ts",
|
|
22
|
+
"typedoc": "typedoc --out docs $(pwd)/src $(pwd)/helper --target es6 --mode file --tsconfig ./tsconfig.json --excludePrivate --excludeProtected --excludeNotExported --exclude '**/*+(spec|bench).ts'",
|
|
23
|
+
"rebuild": "node-gyp rebuild",
|
|
24
|
+
"check": "gts check",
|
|
25
|
+
"clean": "gts clean",
|
|
26
|
+
"compile": "tsc -p . && rollup -c rollup.cjs.config.js && rollup -c rollup.esm.config.js && cpy build/src/*.d.ts dist",
|
|
27
|
+
"compileOG": "mkdirp dist && tsc -p . && rollup -c > dist/node.js && cross-env BROWSER=true rollup -c > dist/browser.js && cpx \"build/src/*.d.ts\" dist",
|
|
28
|
+
"fix": "gts fix",
|
|
29
|
+
"pretest": "npm run compile",
|
|
30
|
+
"posttest": "npm run check"
|
|
31
|
+
},
|
|
32
|
+
"repository": {
|
|
33
|
+
"type": "git",
|
|
34
|
+
"url": "https://github.com/gsknnft/bigint-buffer.git"
|
|
35
|
+
},
|
|
36
|
+
"bugs": {
|
|
37
|
+
"url": "https://github.com/gsknnft/bigint-buffer/issues"
|
|
38
|
+
},
|
|
39
|
+
"homepage": "https://github.com/gsknnft/bigintbuffer",
|
|
40
|
+
"keywords": [
|
|
41
|
+
"bigint",
|
|
42
|
+
"bignum",
|
|
43
|
+
"tc39-bigint",
|
|
44
|
+
"napi"
|
|
45
|
+
],
|
|
46
|
+
"license": "Apache-2.0",
|
|
47
|
+
"dependencies": {
|
|
48
|
+
"bindings": "^1.5.0"
|
|
49
|
+
},
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"@types/benchmark": "^2.1.5",
|
|
52
|
+
"@types/bn.js": "^5.2.0",
|
|
53
|
+
"@types/chai": "^5.2.3",
|
|
54
|
+
"@types/mocha": "^10.0.10",
|
|
55
|
+
"@types/node": "^24.9.1",
|
|
56
|
+
"benchmark": "^2.1.4",
|
|
57
|
+
"bn.js": "^5.2.2",
|
|
58
|
+
"chai": "^4.1.2",
|
|
59
|
+
"coveralls": "^3.1.1",
|
|
60
|
+
"cpy-cli": "^6.0.0",
|
|
61
|
+
"cross-env": "^6.0.3",
|
|
62
|
+
"gts": "^0.8.0",
|
|
63
|
+
"istanbul": "^0.4.1",
|
|
64
|
+
"karma": "^3.0.0",
|
|
65
|
+
"karma-chrome-launcher": "^2.2.0",
|
|
66
|
+
"karma-env-preprocessor": "^0.1.1",
|
|
67
|
+
"karma-mocha": "^1.3.0",
|
|
68
|
+
"karma-mocha-reporter": "^2.2.5",
|
|
69
|
+
"karma-webpack": "^3.0.0",
|
|
70
|
+
"microtime": "^3.0.0",
|
|
71
|
+
"mkdirp": "^0.5.1",
|
|
72
|
+
"mocha": "^5.2.0",
|
|
73
|
+
"pre-commit": "^1.2.2",
|
|
74
|
+
"rollup": "^4.52.5",
|
|
75
|
+
"rollup-plugin-replace": "^2.2.0",
|
|
76
|
+
"ts-loader": "^9.5.4",
|
|
77
|
+
"ts-node": "^10.9.2",
|
|
78
|
+
"typedoc": "^0.28.14",
|
|
79
|
+
"typescript": "5.9.3",
|
|
80
|
+
"webpack": "5.102.1",
|
|
81
|
+
"webpack-cli": "6.0.1"
|
|
82
|
+
},
|
|
83
|
+
"exports": {
|
|
84
|
+
".": {
|
|
85
|
+
"import": "./dist/index.js",
|
|
86
|
+
"require": "./dist/index.cjs",
|
|
87
|
+
"types": "./dist/index.d.ts"
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
"engines": {
|
|
91
|
+
"node": ">=24.0.0"
|
|
92
|
+
},
|
|
93
|
+
"publishConfig": {
|
|
94
|
+
"access": "public"
|
|
95
|
+
},
|
|
96
|
+
"contributors": [
|
|
97
|
+
"Gordon Skinner <gsknnft@gmail.com> (https://github.com/gsknnft)",
|
|
98
|
+
"Michael Wei <mwei@vmware.com> (https://github.com/no2chem)"
|
|
99
|
+
]
|
|
100
|
+
}
|
|
File without changes
|