@gsknnft/bigint-buffer 1.2.0 β 1.3.0
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/.eslintrc +5 -0
- package/README.md +62 -11
- package/dist/node.js +10 -21
- package/helper/bigint.d.ts +2 -2
- package/okg.md +180 -0
- package/package.json +76 -11
- package/rollup.config.js +14 -11
- package/src/conversion/LICENSE +21 -0
- package/src/conversion/README.md +48 -0
- package/src/conversion/docs/README.md +34 -0
- package/src/conversion/docs/functions/base64ToBigint.md +27 -0
- package/src/conversion/docs/functions/bigintToBase64.md +43 -0
- package/src/conversion/docs/functions/bigintToBuf.md +35 -0
- package/src/conversion/docs/functions/bigintToHex.md +43 -0
- package/src/conversion/docs/functions/bigintToText.md +31 -0
- package/src/conversion/docs/functions/bufToBigint.md +25 -0
- package/src/conversion/docs/functions/bufToHex.md +37 -0
- package/src/conversion/docs/functions/bufToText.md +27 -0
- package/src/conversion/docs/functions/hexToBigint.md +29 -0
- package/src/conversion/docs/functions/hexToBuf.md +37 -0
- package/src/conversion/docs/functions/parseHex.md +45 -0
- package/src/conversion/docs/functions/textToBigint.md +27 -0
- package/src/conversion/docs/functions/textToBuf.md +33 -0
- package/src/conversion/docs/functions/toBigIntBE.md +27 -0
- package/src/conversion/docs/functions/toBigIntLE.md +27 -0
- package/src/conversion/docs/functions/toBufferBE.md +33 -0
- package/src/conversion/docs/functions/toBufferLE.md +33 -0
- package/src/conversion/docs/functions/validateBigIntBuffer.md +15 -0
- package/src/conversion/docs/type-aliases/TypedArray.md +11 -0
- package/src/conversion/docs/variables/isNative.md +11 -0
- package/src/conversion/example.cjs +9 -0
- package/src/conversion/example.esm.js +11 -0
- package/src/conversion/package.json +182 -0
- package/src/conversion/pnpm-lock.yaml +5571 -0
- package/src/conversion/tsconfig.rollup.json +9 -0
- package/src/conversion/typedoc.json +5 -0
- package/src/index.bench.ts +116 -119
- package/src/index.spec.ts +44 -78
- package/src/index.ts +40 -35
- package/src/types/bindings.d.t.s +4 -0
- package/tsconfig.json +5 -2
- package/tsconfig.lint.json +5 -0
- package/vitest.config.ts +10 -0
- package/dist/browser.js +0 -75
package/.eslintrc
ADDED
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,78 @@
|
|
|
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.3.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.3.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
|
|
34
85
|
|
|
35
86
|
---
|
|
36
87
|
|
package/dist/node.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
var __importDefault = (undefined && undefined.__importDefault) || function (mod) {
|
|
2
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
3
|
+
};
|
|
3
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
5
|
exports.isNative = void 0;
|
|
5
6
|
exports.toBigIntLE = toBigIntLE;
|
|
@@ -7,24 +8,17 @@ exports.validateBigIntBuffer = validateBigIntBuffer;
|
|
|
7
8
|
exports.toBigIntBE = toBigIntBE;
|
|
8
9
|
exports.toBufferLE = toBufferLE;
|
|
9
10
|
exports.toBufferBE = toBufferBE;
|
|
10
|
-
|
|
11
|
+
// etc.
|
|
12
|
+
const bindings_1 = __importDefault(require("bindings"));
|
|
13
|
+
(0, bindings_1.default)('bigint_buffer');
|
|
11
14
|
exports.isNative = false;
|
|
12
|
-
{
|
|
13
|
-
try {
|
|
14
|
-
converter = require('bindings')('bigint_buffer');
|
|
15
|
-
exports.isNative = !false && 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
15
|
/**
|
|
22
16
|
* Convert a little-endian buffer into a BigInt.
|
|
23
17
|
* @param buf The little-endian buffer to convert
|
|
24
18
|
* @returns A BigInt with the little-endian representation of buf.
|
|
25
19
|
*/
|
|
26
20
|
function toBigIntLE(buf) {
|
|
27
|
-
|
|
21
|
+
{
|
|
28
22
|
const reversed = Buffer.from(buf);
|
|
29
23
|
reversed.reverse();
|
|
30
24
|
const hex = reversed.toString('hex');
|
|
@@ -33,7 +27,6 @@ function toBigIntLE(buf) {
|
|
|
33
27
|
}
|
|
34
28
|
return BigInt(`0x${hex}`);
|
|
35
29
|
}
|
|
36
|
-
return converter.toBigInt(buf, false);
|
|
37
30
|
}
|
|
38
31
|
function validateBigIntBuffer() {
|
|
39
32
|
try {
|
|
@@ -50,14 +43,13 @@ function validateBigIntBuffer() {
|
|
|
50
43
|
* @returns A BigInt with the big-endian representation of buf.
|
|
51
44
|
*/
|
|
52
45
|
function toBigIntBE(buf) {
|
|
53
|
-
|
|
46
|
+
{
|
|
54
47
|
const hex = buf.toString('hex');
|
|
55
48
|
if (hex.length === 0) {
|
|
56
49
|
return BigInt(0);
|
|
57
50
|
}
|
|
58
51
|
return BigInt(`0x${hex}`);
|
|
59
52
|
}
|
|
60
|
-
return converter.toBigInt(buf, true);
|
|
61
53
|
}
|
|
62
54
|
/**
|
|
63
55
|
* Convert a BigInt to a little-endian buffer.
|
|
@@ -66,14 +58,12 @@ function toBigIntBE(buf) {
|
|
|
66
58
|
* @returns A little-endian buffer representation of num.
|
|
67
59
|
*/
|
|
68
60
|
function toBufferLE(num, width) {
|
|
69
|
-
|
|
61
|
+
{
|
|
70
62
|
const hex = num.toString(16);
|
|
71
63
|
const buffer = Buffer.from(hex.padStart(width * 2, '0').slice(0, width * 2), 'hex');
|
|
72
64
|
buffer.reverse();
|
|
73
65
|
return buffer;
|
|
74
66
|
}
|
|
75
|
-
// Allocation is done here, since it is slower using napi in C
|
|
76
|
-
return converter.fromBigInt(num, Buffer.allocUnsafe(width), false);
|
|
77
67
|
}
|
|
78
68
|
/**
|
|
79
69
|
* Convert a BigInt to a big-endian buffer.
|
|
@@ -82,9 +72,8 @@ function toBufferLE(num, width) {
|
|
|
82
72
|
* @returns A big-endian buffer representation of num.
|
|
83
73
|
*/
|
|
84
74
|
function toBufferBE(num, width) {
|
|
85
|
-
|
|
75
|
+
{
|
|
86
76
|
const hex = num.toString(16);
|
|
87
77
|
return Buffer.from(hex.padStart(width * 2, '0').slice(0, width * 2), 'hex');
|
|
88
78
|
}
|
|
89
|
-
return converter.fromBigInt(num, Buffer.allocUnsafe(width), true);
|
|
90
79
|
}
|
package/helper/bigint.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
// not used by code, only for documentation generation (since typedoc can't handle BigInt yet)
|
|
2
|
-
type
|
|
3
|
-
declare const
|
|
2
|
+
type BigIntDoc = number
|
|
3
|
+
declare const BigIntDoc: typeof Number
|
package/okg.md
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "bigint-conversion",
|
|
3
|
+
"version": "2.4.3",
|
|
4
|
+
"description": "Convert to/from BigInt from/to Buffer, ArrayBuffer, hex string, utf8-encoded text string.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"BigInt",
|
|
7
|
+
"bignum",
|
|
8
|
+
"big integer",
|
|
9
|
+
"text",
|
|
10
|
+
"utf8",
|
|
11
|
+
"hex",
|
|
12
|
+
"Buffer",
|
|
13
|
+
"ArrayBuffer",
|
|
14
|
+
"TypedArray"
|
|
15
|
+
],
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"author": {
|
|
18
|
+
"name": "Juan HernΓ‘ndez Serrano",
|
|
19
|
+
"email": "j.hernandez@upc.edu",
|
|
20
|
+
"url": "https://github.com/juanelas"
|
|
21
|
+
},
|
|
22
|
+
"repository": "github:juanelas/bigint-conversion",
|
|
23
|
+
"main": "./dist/cjs/index.node.js",
|
|
24
|
+
"browser": "./dist/esm/index.browser.js",
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"exports": {
|
|
27
|
+
".": {
|
|
28
|
+
"node": {
|
|
29
|
+
"import": {
|
|
30
|
+
"types": "./dist/index.d.ts",
|
|
31
|
+
"default": "./dist/esm/index.node.js"
|
|
32
|
+
},
|
|
33
|
+
"require": {
|
|
34
|
+
"types": "./dist/index.d.ts",
|
|
35
|
+
"default": "./dist/cjs/index.node.js"
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"script": "./dist/bundle.iife.js",
|
|
39
|
+
"default": {
|
|
40
|
+
"types": "./dist/index.d.ts",
|
|
41
|
+
"default": "./dist/esm/index.browser.js"
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"./esm-browser-bundle": "./dist/esm/bundle.min.js",
|
|
45
|
+
"./dist/esm/bundle.min.js": "./dist/esm/bundle.min.js",
|
|
46
|
+
"./esm-browser-bundle-nomin": "./dist/esm/bundle.js",
|
|
47
|
+
"./dist/esm/bundle.js": "./dist/esm/bundle.js",
|
|
48
|
+
"./iife-browser-bundle": "./dist/bundle.iife.js",
|
|
49
|
+
"./dist/bundle.iife.js": "./dist/bundle.iife.js",
|
|
50
|
+
"./umd-browser-bundle": "./dist/bundle.umd.js",
|
|
51
|
+
"./dist/bundle.umd.js": "./dist/bundle.umd.js",
|
|
52
|
+
"./dist/cjs/index.node": {
|
|
53
|
+
"types": "./dist/index.d.ts",
|
|
54
|
+
"default": "./dist/cjs/index.node.js"
|
|
55
|
+
},
|
|
56
|
+
"./dist/esm/index.node": {
|
|
57
|
+
"types": "./dist/index.d.ts",
|
|
58
|
+
"default": "./dist/esm/index.node.js"
|
|
59
|
+
},
|
|
60
|
+
"./dist/esm/index.browser": {
|
|
61
|
+
"types": "./dist/index.d.ts",
|
|
62
|
+
"default": "./dist/esm/index.browser.js"
|
|
63
|
+
},
|
|
64
|
+
"./package.json": "./package.json"
|
|
65
|
+
},
|
|
66
|
+
"imports": {
|
|
67
|
+
"#pkg": {
|
|
68
|
+
"require": {
|
|
69
|
+
"types": "./dist/index.d.ts",
|
|
70
|
+
"default": "./dist/cjs/index.node.js"
|
|
71
|
+
},
|
|
72
|
+
"import": {
|
|
73
|
+
"types": "./dist/index.d.ts",
|
|
74
|
+
"default": "./dist/esm/index.node.js"
|
|
75
|
+
},
|
|
76
|
+
"default": {
|
|
77
|
+
"types": "./dist/index.d.ts",
|
|
78
|
+
"default": "./dist/esm/index.browser.js"
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
"directories": {
|
|
83
|
+
"build": "./build",
|
|
84
|
+
"dist": "./dist",
|
|
85
|
+
"docs": "./docs",
|
|
86
|
+
"src": "./src",
|
|
87
|
+
"test": "./test",
|
|
88
|
+
"benchmark": "./benchmark",
|
|
89
|
+
"mocha-ts": "./.mocha-ts"
|
|
90
|
+
},
|
|
91
|
+
"scripts": {
|
|
92
|
+
"_build:cleantypes": "rimraf .types",
|
|
93
|
+
"_build:cjsAndesmPkgJsons": "node ./build/bin/post-build.js",
|
|
94
|
+
"build": "run-s lint:src build:js lint:test docs",
|
|
95
|
+
"build:js": "rollup -c build/rollup.config.mjs",
|
|
96
|
+
"postbuild:js": "run-s _build:cleantypes _build:cjsAndesmPkgJsons",
|
|
97
|
+
"clean": "rimraf .mocha-ts coverage dist .types docs",
|
|
98
|
+
"coverage": "c8 --clean --check-coverage --exclude \"{src/ts/**/*.spec.ts,src/ts/**/*.test.ts,test,test-vectors,build}\" --exclude-after-remap --reporter=text --reporter=lcov node ./build/bin/mocha-ts.js --commonjs ",
|
|
99
|
+
"docs": "node build/build.docs.js",
|
|
100
|
+
"git:add": "git add -A",
|
|
101
|
+
"lint": "ts-standard --fix",
|
|
102
|
+
"lint:src": "ts-standard --fix \"src/**/!(*.spec|*.test).ts\"",
|
|
103
|
+
"lint:test": "ts-standard --fix \"{test/**/*.ts,src/**/*.spec.ts,src/**/*.test.ts}\"",
|
|
104
|
+
"mocha-ts": "node --experimental-modules --experimental-json-modules --es-module-specifier-resolution=node ./build/bin/mocha-ts.js ",
|
|
105
|
+
"mocha-ts:cjs": "node ./build/bin/mocha-ts.js --commonjs ",
|
|
106
|
+
"mocha-ts:watch": "npm run mocha-ts:cjs -- --watch --timeout 0",
|
|
107
|
+
"mocha-ts:browser": "node build/testing/browser/index.js ",
|
|
108
|
+
"mocha-ts:browser-headless": "node build/testing/browser/index.js headless ",
|
|
109
|
+
"preversion": "run-s clean lint:src build:js lint:test coverage test:browser-headless",
|
|
110
|
+
"version": "run-s docs git:add",
|
|
111
|
+
"postversion": "git push --follow-tags",
|
|
112
|
+
"test": "run-s test:node test:browser-headless",
|
|
113
|
+
"test:browser": "npm run mocha-ts:browser",
|
|
114
|
+
"test:browser-headless": "npm run mocha-ts:browser-headless",
|
|
115
|
+
"test:node": "run-s test:node-cjs test:node-esm",
|
|
116
|
+
"test:node-cjs": "npm run mocha-ts:cjs ",
|
|
117
|
+
"test:node-esm": "npm run mocha-ts ",
|
|
118
|
+
"watch": "npm run mocha-ts:watch "
|
|
119
|
+
},
|
|
120
|
+
"ts-standard": {
|
|
121
|
+
"project": "tsconfig.json",
|
|
122
|
+
"env": [
|
|
123
|
+
"mocha"
|
|
124
|
+
],
|
|
125
|
+
"globals": [
|
|
126
|
+
"IS_BROWSER",
|
|
127
|
+
"browser",
|
|
128
|
+
"page",
|
|
129
|
+
"chai"
|
|
130
|
+
],
|
|
131
|
+
"ignore": [
|
|
132
|
+
"dist/**/*",
|
|
133
|
+
"examples/**/*",
|
|
134
|
+
"types/**/*",
|
|
135
|
+
"benchmark/**/*"
|
|
136
|
+
]
|
|
137
|
+
},
|
|
138
|
+
"nodeBrowserSkel": {
|
|
139
|
+
"badges": {
|
|
140
|
+
"workflow": true,
|
|
141
|
+
"coveralls": true
|
|
142
|
+
},
|
|
143
|
+
"git": {
|
|
144
|
+
"branch": "main"
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
"devDependencies": {
|
|
148
|
+
"@rollup/plugin-commonjs": "^25.0.7",
|
|
149
|
+
"@rollup/plugin-inject": "^5.0.5",
|
|
150
|
+
"@rollup/plugin-json": "^6.0.1",
|
|
151
|
+
"@rollup/plugin-multi-entry": "^6.0.1",
|
|
152
|
+
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
153
|
+
"@rollup/plugin-replace": "^5.0.5",
|
|
154
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
155
|
+
"@rollup/plugin-typescript": "^11.1.5",
|
|
156
|
+
"@types/chai": "^4.3.10",
|
|
157
|
+
"@types/mocha": "^10.0.4",
|
|
158
|
+
"c8": "^8.0.1",
|
|
159
|
+
"chai": "^4.3.10",
|
|
160
|
+
"dotenv": "^16.3.1",
|
|
161
|
+
"glob": "^10.3.10",
|
|
162
|
+
"json5": "^2.2.3",
|
|
163
|
+
"minimatch": "^9.0.3",
|
|
164
|
+
"mocha": "^10.2.0",
|
|
165
|
+
"npm-run-all": "^4.1.5",
|
|
166
|
+
"pirates": "^4.0.6",
|
|
167
|
+
"puppeteer": "^21.5.1",
|
|
168
|
+
"rimraf": "^5.0.5",
|
|
169
|
+
"rollup": "^4.3.0",
|
|
170
|
+
"rollup-plugin-dts": "^6.1.0",
|
|
171
|
+
"ts-standard": "^12.0.2",
|
|
172
|
+
"tslib": "^2.6.2",
|
|
173
|
+
"typedoc": "^0.25.3",
|
|
174
|
+
"typedoc-plugin-markdown": "^3.17.1",
|
|
175
|
+
"typescript": "^5.0.0"
|
|
176
|
+
},
|
|
177
|
+
"dependencies": {
|
|
178
|
+
"@juanelas/base64": "^1.1.2"
|
|
179
|
+
}
|
|
180
|
+
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gsknnft/bigint-buffer",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "bigint to buffer conversion with native support",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
|
-
"type": "module",
|
|
7
6
|
"browser": {
|
|
8
7
|
"./dist/node.js": "./dist/browser.js"
|
|
9
8
|
},
|
|
9
|
+
"directories": {
|
|
10
|
+
"build": "./build",
|
|
11
|
+
"dist": "./dist",
|
|
12
|
+
"docs": "./docs",
|
|
13
|
+
"src": "./src",
|
|
14
|
+
"test": "./test",
|
|
15
|
+
"benchmark": "./benchmark",
|
|
16
|
+
"mocha-ts": "./.mocha-ts"
|
|
17
|
+
},
|
|
10
18
|
"types": "dist/index.d.ts",
|
|
11
19
|
"repository": {
|
|
12
20
|
"type": "git",
|
|
@@ -24,22 +32,36 @@
|
|
|
24
32
|
],
|
|
25
33
|
"license": "Apache-2.0",
|
|
26
34
|
"dependencies": {
|
|
35
|
+
"@juanelas/base64": "^1.1.5",
|
|
27
36
|
"bindings": "^1.5.0"
|
|
28
37
|
},
|
|
29
38
|
"devDependencies": {
|
|
39
|
+
"@rollup/plugin-commonjs": "^28.0.9",
|
|
40
|
+
"@rollup/plugin-inject": "^5.0.5",
|
|
41
|
+
"@rollup/plugin-json": "^6.1.0",
|
|
42
|
+
"@rollup/plugin-multi-entry": "^7.0.1",
|
|
43
|
+
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
44
|
+
"@rollup/plugin-replace": "^6.0.2",
|
|
45
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
46
|
+
"@rollup/plugin-typescript": "^12.3.0",
|
|
30
47
|
"@types/benchmark": "^2.1.5",
|
|
48
|
+
"@types/bindings": "^1.5.5",
|
|
31
49
|
"@types/bn.js": "^5.2.0",
|
|
32
50
|
"@types/chai": "^5.2.3",
|
|
33
51
|
"@types/mocha": "^10.0.10",
|
|
34
52
|
"@types/node": "^24.9.1",
|
|
35
53
|
"benchmark": "^2.1.4",
|
|
36
54
|
"bn.js": "^5.2.2",
|
|
37
|
-
"
|
|
55
|
+
"c8": "^10.1.3",
|
|
56
|
+
"chai": "^6.2.0",
|
|
38
57
|
"coveralls": "^3.1.1",
|
|
39
58
|
"cpy-cli": "^6.0.0",
|
|
40
59
|
"cross-env": "^6.0.3",
|
|
60
|
+
"glob": "^11.0.3",
|
|
41
61
|
"gts": "^0.8.0",
|
|
42
62
|
"istanbul": "^0.4.1",
|
|
63
|
+
"jsdom": "^27.0.1",
|
|
64
|
+
"json5": "^2.2.3",
|
|
43
65
|
"karma": "^3.0.0",
|
|
44
66
|
"karma-chrome-launcher": "^2.2.0",
|
|
45
67
|
"karma-env-preprocessor": "^0.1.1",
|
|
@@ -47,23 +69,39 @@
|
|
|
47
69
|
"karma-mocha-reporter": "^2.2.5",
|
|
48
70
|
"karma-webpack": "^3.0.0",
|
|
49
71
|
"microtime": "^3.0.0",
|
|
72
|
+
"minimatch": "^10.0.3",
|
|
50
73
|
"mkdirp": "^0.5.1",
|
|
51
|
-
"mocha": "^
|
|
74
|
+
"mocha": "^11.7.4",
|
|
75
|
+
"npm-run-all": "^4.1.5",
|
|
76
|
+
"pirates": "^4.0.7",
|
|
52
77
|
"pre-commit": "^1.2.2",
|
|
78
|
+
"puppeteer": "^24.26.1",
|
|
79
|
+
"rimraf": "^6.0.1",
|
|
53
80
|
"rollup": "^4.52.5",
|
|
54
|
-
"rollup-plugin-
|
|
81
|
+
"rollup-plugin-dts": "^6.2.3",
|
|
82
|
+
"rollup-plugin-esbuild": "^6.2.1",
|
|
55
83
|
"ts-loader": "^9.5.4",
|
|
56
84
|
"ts-node": "^10.9.2",
|
|
85
|
+
"ts-standard": "^12.0.2",
|
|
86
|
+
"tslib": "^2.8.1",
|
|
57
87
|
"typedoc": "^0.28.14",
|
|
88
|
+
"typedoc-plugin-markdown": "^4.9.0",
|
|
58
89
|
"typescript": "5.9.3",
|
|
90
|
+
"vite": "^7.1.12",
|
|
91
|
+
"vitest": "^4.0.3",
|
|
59
92
|
"webpack": "5.102.1",
|
|
60
93
|
"webpack-cli": "6.0.1"
|
|
61
94
|
},
|
|
62
95
|
"exports": {
|
|
63
96
|
".": {
|
|
97
|
+
"types": "./dist/index.d.ts",
|
|
64
98
|
"import": "./dist/index.js",
|
|
65
|
-
"require": "./dist/index.cjs"
|
|
66
|
-
|
|
99
|
+
"require": "./dist/index.cjs"
|
|
100
|
+
},
|
|
101
|
+
"./conversion": {
|
|
102
|
+
"types": "./dist/conversion/index.d.ts",
|
|
103
|
+
"import": "./dist/conversion/index.js",
|
|
104
|
+
"require": "./dist/conversion/index.cjs"
|
|
67
105
|
}
|
|
68
106
|
},
|
|
69
107
|
"engines": {
|
|
@@ -77,10 +115,37 @@
|
|
|
77
115
|
"Michael Wei <mwei@vmware.com> (https://github.com/no2chem)"
|
|
78
116
|
],
|
|
79
117
|
"scripts": {
|
|
118
|
+
"_build:cleantypes": "rimraf .types",
|
|
119
|
+
"_build:cjsAndesmPkgJsons": "node ./build/bin/post-build.js",
|
|
120
|
+
"build": "run-s lint:src build:js lint:test docs",
|
|
121
|
+
"build:js": "rollup -c build/rollup.config.mjs",
|
|
122
|
+
"postbuild:js": "run-s _build:cleantypes _build:cjsAndesmPkgJsons",
|
|
123
|
+
"clean": "rimraf .mocha-ts coverage dist .types docs",
|
|
124
|
+
"coverage": "c8 --clean --check-coverage --exclude \"{src/ts/**/*.spec.ts,src/ts/**/*.test.ts,test,test-vectors,build}\" --exclude-after-remap --reporter=text --reporter=lcov node ./build/bin/mocha-ts.js --commonjs ",
|
|
125
|
+
"docs": "node build/build.docs.js",
|
|
126
|
+
"git:add": "git add -A",
|
|
127
|
+
"lint": "ts-standard --fix",
|
|
128
|
+
"lint:src": "ts-standard --fix \"src/**/!(*.spec|*.test).ts\"",
|
|
129
|
+
"lint:test": "ts-standard --fix \"{test/**/*.ts,src/**/*.spec.ts,src/**/*.test.ts}\"",
|
|
130
|
+
"mocha-ts": "node --experimental-modules --experimental-json-modules --es-module-specifier-resolution=node ./build/bin/mocha-ts.js ",
|
|
131
|
+
"mocha-ts:cjs": "node ./build/bin/mocha-ts.js --commonjs ",
|
|
132
|
+
"mocha-ts:watch": "npm run mocha-ts:cjs -- --watch --timeout 0",
|
|
133
|
+
"mocha-ts:browser": "node build/testing/browser/index.js ",
|
|
134
|
+
"mocha-ts:browser-headless": "node build/testing/browser/index.js headless ",
|
|
135
|
+
"preversion": "run-s clean lint:src build:js lint:test coverage test:browser-headless",
|
|
136
|
+
"version": "run-s docs git:add",
|
|
137
|
+
"postversion": "git push --follow-tags",
|
|
138
|
+
"test:conv": "run-s test:node test:browser-headless",
|
|
139
|
+
"test:browser:conv": "npm run mocha-ts:browser",
|
|
140
|
+
"test:browser-headless": "npm run mocha-ts:browser-headless",
|
|
141
|
+
"test:node:conv": "run-s test:node-cjs test:node-esm",
|
|
142
|
+
"test:node-cjs": "npm run mocha-ts:cjs ",
|
|
143
|
+
"test:node-esm": "npm run mocha-ts ",
|
|
144
|
+
"watch": "npm run mocha-ts:watch ",
|
|
80
145
|
"test": "npm run test:node && npm run test:browser",
|
|
81
|
-
"coverage": "istanbul cover ./test/index.js",
|
|
146
|
+
"coverage:istan": "istanbul cover ./test/index.js",
|
|
82
147
|
"coveralls": "npm run coverage && coveralls <coverage/lcov.info",
|
|
83
|
-
"lint": "gts check",
|
|
148
|
+
"lint:gts": "gts check",
|
|
84
149
|
"install": "npm run rebuild || echo \"Couldn't build bindings. Non-native version used.\"",
|
|
85
150
|
"test:browser": "karma start karma.conf.js",
|
|
86
151
|
"test:node": "mocha -r ts-node/register src/**/*.spec.ts --timeout 40000",
|
|
@@ -88,8 +153,8 @@
|
|
|
88
153
|
"typedoc": "typedoc --out docs $(pwd)/src $(pwd)/helper --target es6 --mode file --tsconfig ./tsconfig.json --excludePrivate --excludeProtected --excludeNotExported --exclude '**/*+(spec|bench).ts'",
|
|
89
154
|
"rebuild": "node-gyp rebuild",
|
|
90
155
|
"check": "gts check",
|
|
91
|
-
"clean": "gts clean",
|
|
92
|
-
"compile": "tsc -p . && rollup -c
|
|
156
|
+
"clean:gts": "gts clean",
|
|
157
|
+
"compile": "tsc -p . && rollup -c && cross-env BROWSER=true rollup -c && cpy \"build/src/*.d.ts\" dist || echo \"No .d.ts files to copy\"",
|
|
93
158
|
"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",
|
|
94
159
|
"fix": "gts fix",
|
|
95
160
|
"pretest": "npm run compile",
|
package/rollup.config.js
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
import replace from 'rollup
|
|
1
|
+
import replace from '@rollup/plugin-replace';
|
|
2
2
|
|
|
3
3
|
export default {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
4
|
+
input: 'build/src/index.js',
|
|
5
|
+
output: {
|
|
6
|
+
format: 'esm',
|
|
7
|
+
file: 'dist/node.js'
|
|
8
|
+
},
|
|
9
|
+
external: ['bindings'], // β This is the fix
|
|
10
|
+
plugins: [
|
|
11
|
+
replace({
|
|
12
|
+
preventAssignment: true,
|
|
13
|
+
'process.browser': JSON.stringify(process.env.BROWSER === 'true')
|
|
14
|
+
})
|
|
15
|
+
]
|
|
16
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2018 Juan HernΓ‘ndez Serrano
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
[](https://opensource.org/licenses/MIT)
|
|
2
|
+
[](CODE_OF_CONDUCT.md)
|
|
3
|
+
[](https://standardjs.com)
|
|
4
|
+
[](https://github.com/juanelas/bigint-conversion/actions/workflows/build-and-test.yml)
|
|
5
|
+
[](https://coveralls.io/github/juanelas/bigint-conversion?branch=main)
|
|
6
|
+
|
|
7
|
+
# bigint-conversion
|
|
8
|
+
|
|
9
|
+
Convert to/from non-negative integers represented with [ES-2020 native JS implementation of BigInt](https://tc39.es/ecma262/#sec-bigint-objects) from/to:
|
|
10
|
+
|
|
11
|
+
- `Buffer` (node.js) or `ArrayBuffer|TypedArray` (native js),
|
|
12
|
+
- hex `string`,
|
|
13
|
+
- utf8-encoded text `string`,
|
|
14
|
+
- standard and url-safe base64 with and without padding.
|
|
15
|
+
|
|
16
|
+
It provides a common interface for the conversions that works for both **node.js** and **native javascript**.
|
|
17
|
+
|
|
18
|
+
> Note that there is not a directly visible `TypedArray()` constructor, but a set of typed array ones: `Int8Array()`, `Uint8Array()`, `Uint8ClampedArray()`, `Int16Array()`, `Uint16Array()`, `Int32Array()`, `Uint32Array()`, `Float32Array()`, `Float64Array()`, `BigInt64Array()`, `BigUint64Array()`.
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
`bigint-conversion` can be imported to your project with `npm`:
|
|
23
|
+
|
|
24
|
+
```console
|
|
25
|
+
npm install bigint-conversion
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Then either require (Node.js CJS):
|
|
29
|
+
|
|
30
|
+
```javascript
|
|
31
|
+
const bigintConversion = require('bigint-conversion')
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
or import (JavaScript ES module):
|
|
35
|
+
|
|
36
|
+
```javascript
|
|
37
|
+
import * as bigintConversion from 'bigint-conversion'
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
The appropriate version for browser or node is automatically exported.
|
|
41
|
+
|
|
42
|
+
> BigInt is [ES-2020](https://tc39.es/ecma262/#sec-bigint-objects). In order to use it with TypeScript you should set `target` (and probably also `lib`) to at least `es2020` in `tsconfig.json`.
|
|
43
|
+
|
|
44
|
+
You can also download the [IIFE bundle](https://raw.githubusercontent.com/juanelas/bigint-conversion/main/dist\bundle.iife.js), the [ESM bundle](https://raw.githubusercontent.com/juanelas/bigint-conversion/main/dist\esm\bundle.min.js) or the [UMD bundle](https://raw.githubusercontent.com/juanelas/bigint-conversion/main/dist\bundle.umd.js) and manually add it to your project, or, if you have already installed `bigint-conversion` in your project, just get the bundles from `node_modules/bigint-conversion/dist/bundles/`.
|
|
45
|
+
|
|
46
|
+
## API reference documentation
|
|
47
|
+
|
|
48
|
+
[Check the API](./docs/API.md)
|