@gsknnft/bigint-buffer 1.4.3 → 1.4.5

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.
Files changed (48) hide show
  1. package/README.md +98 -89
  2. package/build/Release/bigint_buffer.iobj +0 -0
  3. package/build/Release/bigint_buffer.ipdb +0 -0
  4. package/build/Release/bigint_buffer.node +0 -0
  5. package/build/Release/bigint_buffer.pdb +0 -0
  6. package/build/Release/obj/bigint_buffer/src/bigint-buffer.obj +0 -0
  7. package/build/Release/obj/bigint_buffer/win_delay_load_hook.obj +0 -0
  8. package/build/binding.sln +3 -3
  9. package/build/conversion/index.js +18 -0
  10. package/build/conversion/index.js.map +1 -0
  11. package/build/conversion/src/ts/fixedPoint/index.d.ts +12 -0
  12. package/build/conversion/src/ts/fixedPoint/index.js +79 -0
  13. package/build/conversion/src/ts/fixedPoint/index.js.map +1 -0
  14. package/build/conversion/src/ts/index.d.ts +169 -0
  15. package/build/conversion/src/ts/index.js +453 -0
  16. package/build/conversion/src/ts/index.js.map +1 -0
  17. package/build/conversion/test/bigintToBase64.test.js +72 -0
  18. package/build/conversion/test/bigintToBase64.test.js.map +1 -0
  19. package/build/conversion/test/bigintToBuf.test.js +77 -0
  20. package/build/conversion/test/bigintToBuf.test.js.map +1 -0
  21. package/build/conversion/test/bigintToHex.test.js +86 -0
  22. package/build/conversion/test/bigintToHex.test.js.map +1 -0
  23. package/build/conversion/test/bigintToText.test.js +63 -0
  24. package/build/conversion/test/bigintToText.test.js.map +1 -0
  25. package/build/conversion/test/bufToBigint.test.js +55 -0
  26. package/build/conversion/test/bufToBigint.test.js.map +1 -0
  27. package/build/conversion/test/hexToBigint.test.js +56 -0
  28. package/build/conversion/test/hexToBigint.test.js.map +1 -0
  29. package/build/conversion/test/hexToBuf.test.js +73 -0
  30. package/build/conversion/test/hexToBuf.test.js.map +1 -0
  31. package/build/conversion/test/parseHex.test.js +69 -0
  32. package/build/conversion/test/parseHex.test.js.map +1 -0
  33. package/build/conversion/test/textToBuf.test.js +59 -0
  34. package/build/conversion/test/textToBuf.test.js.map +1 -0
  35. package/build/index.js +242 -0
  36. package/build/index.js.map +1 -0
  37. package/dist/index.cjs +1 -1
  38. package/dist/index.js +257 -200
  39. package/dist/index.umd.js +1 -1
  40. package/dist/tsconfig.tsbuildinfo +1 -1
  41. package/dist/types/conversion/src/ts/fixedPoint/index.d.ts +12 -0
  42. package/dist/types/conversion/src/ts/index.d.ts +1 -0
  43. package/package.json +132 -132
  44. package/src/conversion/docs/README.md +9 -1
  45. package/src/conversion/src/docs/index.md +6 -1
  46. package/src/conversion/src/ts/fixedPoint/index.ts +87 -0
  47. package/src/conversion/src/ts/index.ts +15 -0
  48. /package/dist/types/dist/dist/{types/index.d.ts → index.d.ts} +0 -0
package/README.md CHANGED
@@ -1,89 +1,98 @@
1
- ![CI](https://github.com/gsknknft/bigint-buffer/actions/workflows/ci.yaml/badge.svg)
2
- ![Release](https://github.com/gsknknft/bigint-buffer/actions/workflows/release.yaml/badge.svg)
3
-
4
- # @gsknnft/bigint-buffer
5
-
6
- 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`.
7
-
8
- > **Upgrade notice:** Use `@gsknnft/bigint-buffer@1.4.3+` for verified bindings, fresh CI, and npm-based workflows across Node 18–24.
9
-
10
- [![NPM Version](https://img.shields.io/npm/v/@gsknnft/bigint-buffer.svg?style=flat-square)](https://www.npmjs.com/package/@gsknnft/bigint-buffer)
11
- [![Node Version](https://img.shields.io/node/v/@gsknnft/bigint-buffer.svg?style=flat-square)](https://nodejs.org)
12
-
13
- ---
14
-
15
- ## Why This Package
16
- - Native N-API binding with pure-JS fallback for browsers and constrained environments.
17
- - Conversion helpers from `bigint-conversion` in-core (no extra deps).
18
- - ESM and CJS exports plus a UMD/browser bundle.
19
- - Actively maintained; legacy `bigint-buffer` is deprecated and flagged by audits.
20
-
21
- ---
22
-
23
- ## Install
24
- ```bash
25
- npm install @gsknnft/bigint-buffer
26
- # or pnpm/yarn if preferred
27
- ```
28
-
29
- ---
30
-
31
- ## Quick Start
32
- ```ts
33
- import {
34
- toBigIntBE, toBigIntLE, toBufferBE, toBufferLE,
35
- bigintToBuf, bufToBigint, bigintToHex, hexToBigint,
36
- bigintToText, textToBigint, bigintToBase64, base64ToBigint,
37
- } from "@gsknnft/bigint-buffer";
38
-
39
- toBigIntBE(Buffer.from("deadbeef", "hex")); // 3735928559n
40
- toBufferLE(0xdeadbeefn, 6); // <Buffer ef be ad de 00 00>
41
- bigintToHex(123456789n); // "075bcd15"
42
- textToBigint("Hello"); // 0x48656c6c6f
43
- bigintToBase64(123456789n); // "B1vNFQ=="
44
- ```
45
-
46
- ### Conversion Utilities
47
- ```ts
48
- import { conversionUtils } from "@gsknnft/bigint-buffer";
49
-
50
- const arrBuf = conversionUtils.bigintToBuf(123456789n, true); // ArrayBuffer
51
- const hex = conversionUtils.bigintToHex(123456789n, true); // '0x...' format
52
- const text = conversionUtils.bigintToText(123456789n);
53
- ```
54
-
55
- ---
56
-
57
- ## Runtime
58
- - Native binary: `build/Release/bigint_buffer.node` (loads automatically when available).
59
- - Fallback: pure JS bundle for browser and non-native installs.
60
- - Check which path loaded:
61
- ```ts
62
- import { isNative } from "@gsknnft/bigint-buffer";
63
- console.log(isNative); // true when native binding is active
64
- ```
65
-
66
- ---
67
-
68
- ## Commands
69
- ```bash
70
- npm run build # bundle + declarations + type check
71
- npm test # vitest with coverage
72
- npm run test:node # mocha against built JS (after build/compile)
73
- npm run rebuild:native # rebuild the N-API binding
74
- ```
75
-
76
- ---
77
-
78
- ## API Surface (high level)
79
- - Core: `toBigIntBE/LE`, `toBufferBE/LE`, `validateBigIntBuffer`, `isNative`
80
- - Conversion: `bigintToBuf`, `bufToBigint`, `bigintToHex`, `hexToBigint`, `bigintToText`, `textToBigint`, `bigintToBase64`, `base64ToBigint`, `bufToHex`, `hexToBuf`, `textToBuf`, `bufToText`, `parseHex`
81
-
82
- All helpers are endian-safe and validated across Node and browser builds.
83
-
84
- ---
85
-
86
- ## Support
87
- - Version: 1.4.3
88
- - Node: 18+ (tested through 24 LTS)
89
- - Issues: https://github.com/gsknnft/bigint-buffer/issues
1
+ ![CI](https://github.com/gsknknft/bigint-buffer/actions/workflows/ci.yaml/badge.svg)
2
+ ![Release](https://github.com/gsknknft/bigint-buffer/actions/workflows/release.yaml/badge.svg)
3
+
4
+ # @gsknnft/bigint-buffer
5
+
6
+ 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`.
7
+
8
+ **Upgrade notice:** `1.4.5` adds FixedPoint utilities, native bindings in `build/Release/` out of the box, and improved JS fallback for environments without native support. CI-verified for Node 20–24. All users should upgrade for best compatibility and new features.
9
+
10
+ [![NPM Version](https://img.shields.io/npm/v/@gsknnft/bigint-buffer.svg?style=flat-square)](https://www.npmjs.com/package/@gsknnft/bigint-buffer)
11
+ [![Node Version](https://img.shields.io/node/v/@gsknnft/bigint-buffer.svg?style=flat-square)](https://nodejs.org)
12
+
13
+ ---
14
+
15
+ ## Why This Package
16
+
17
+ - Native N-API binding with pure-JS fallback for browsers and constrained environments.
18
+ - Conversion helpers from `bigint-conversion` in-core (no extra deps).
19
+ - ESM and CJS exports plus a UMD/browser bundle.
20
+ - Actively maintained; legacy `bigint-buffer` is deprecated and flagged by audits.
21
+
22
+ ---
23
+
24
+ ## Install
25
+ ```bash
26
+ npm install @gsknnft/bigint-buffer
27
+ # or pnpm/yarn if preferred
28
+ ```
29
+
30
+ ---
31
+
32
+ ## Quick Start
33
+ ```ts
34
+ import {
35
+ toBigIntBE, toBigIntLE, toBufferBE, toBufferLE,
36
+ bigintToBuf, bufToBigint, bigintToHex, hexToBigint,
37
+ bigintToText, textToBigint, bigintToBase64, base64ToBigint,
38
+ // New in 1.4.5
39
+ toFixedPoint, fromFixedPoint, addFixedPoint, subtractFixedPoint,
40
+ averageFixedPoint, compareFixedPoint, type FixedPoint,
41
+ } from "@gsknnft/bigint-buffer";
42
+
43
+ toBigIntBE(Buffer.from("deadbeef", "hex")); // 3735928559n
44
+ toBufferLE(0xdeadbeefn, 6); // <Buffer ef be ad de 00 00>
45
+ bigintToHex(123456789n); // "075bcd15"
46
+ textToBigint("Hello"); // 0x48656c6c6f
47
+ bigintToBase64(123456789n); // "B1vNFQ=="
48
+
49
+ // FixedPoint usage
50
+ const fp = toFixedPoint(123456789n, 18); // Convert bigint to FixedPoint
51
+ const sum = addFixedPoint(fp, fp); // Add two FixedPoints
52
+ const avg = averageFixedPoint([fp, fp]); // Average FixedPoints
53
+ ```
54
+
55
+ ### Conversion Utilities
56
+ ```ts
57
+ import { conversionUtils } from "@gsknnft/bigint-buffer";
58
+
59
+ const arrBuf = conversionUtils.bigintToBuf(123456789n, true); // ArrayBuffer
60
+ const hex = conversionUtils.bigintToHex(123456789n, true); // '0x...' format
61
+ const text = conversionUtils.bigintToText(123456789n);
62
+ ```
63
+
64
+ ---
65
+
66
+ ## Runtime
67
+ - Native binary: `build/Release/bigint_buffer.node` (included in npm package; loads automatically when available).
68
+ - Fallback: pure JS bundle for browser and non-native installs (now improved in 1.4.5).
69
+ - Check which path loaded:
70
+ ```ts
71
+ import { isNative } from "@gsknnft/bigint-buffer";
72
+ console.log(isNative); // true when native binding is active
73
+ ```
74
+
75
+ ---
76
+
77
+ ## Commands
78
+ ```bash
79
+ npm run build # bundle + declarations + type check
80
+ npm test # vitest with coverage
81
+ npm run test:node # mocha against built JS (after build/compile)
82
+ npm run rebuild:native # rebuild the N-API binding
83
+ ```
84
+
85
+ ---
86
+
87
+ ## API Surface (high level)
88
+ - Core: `toBigIntBE/LE`, `toBufferBE/LE`, `validateBigIntBuffer`, `isNative`
89
+ - Conversion: `bigintToBuf`, `bufToBigint`, `bigintToHex`, `hexToBigint`, `bigintToText`, `textToBigint`, `bigintToBase64`, `base64ToBigint`, `bufToHex`, `hexToBuf`, `textToBuf`, `bufToText`, `parseHex`
90
+
91
+ All helpers are endian-safe and validated across Node and browser builds.
92
+
93
+ ---
94
+
95
+ ## Support
96
+ - Version: 1.4.5 (FixedPoint, native bindings out-of-the-box, improved JS fallback)
97
+ - Node: 20+ (tested through 24 LTS under CI)
98
+ - Issues: https://github.com/gsknnft/bigint-buffer/issues
Binary file
Binary file
Binary file
Binary file
package/build/binding.sln CHANGED
@@ -4,14 +4,14 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "bigint_buffer", "bigint_buf
4
4
  EndProject
5
5
  Global
6
6
  GlobalSection(SolutionConfigurationPlatforms) = preSolution
7
- Release|x64 = Release|x64
8
7
  Debug|x64 = Debug|x64
8
+ Release|x64 = Release|x64
9
9
  EndGlobalSection
10
10
  GlobalSection(ProjectConfigurationPlatforms) = postSolution
11
- {24113E9C-F3B8-A9AC-DC29-9757A019F33F}.Release|x64.ActiveCfg = Release|x64
12
- {24113E9C-F3B8-A9AC-DC29-9757A019F33F}.Release|x64.Build.0 = Release|x64
13
11
  {24113E9C-F3B8-A9AC-DC29-9757A019F33F}.Debug|x64.ActiveCfg = Debug|x64
14
12
  {24113E9C-F3B8-A9AC-DC29-9757A019F33F}.Debug|x64.Build.0 = Debug|x64
13
+ {24113E9C-F3B8-A9AC-DC29-9757A019F33F}.Release|x64.ActiveCfg = Release|x64
14
+ {24113E9C-F3B8-A9AC-DC29-9757A019F33F}.Release|x64.Build.0 = Release|x64
15
15
  EndGlobalSection
16
16
  GlobalSection(SolutionProperties) = preSolution
17
17
  HideSolutionNode = FALSE
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./src/ts/index"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/conversion/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iDAA+B"}
@@ -0,0 +1,12 @@
1
+ export type FixedPoint = string;
2
+ export declare const FIXED_POINT_DECIMALS = 9;
3
+ export declare const FIXED_POINT_PATTERN: RegExp;
4
+ export declare const ZERO_FIXED_POINT: FixedPoint;
5
+ export declare const toBigIntValue: (value?: FixedPoint) => bigint;
6
+ export declare function toFixedPoint(value: number, decimals?: number): FixedPoint;
7
+ export declare function fromFixedPoint(value?: FixedPoint, decimals?: number): number;
8
+ export declare function addFixedPoint(a: FixedPoint, b: FixedPoint): FixedPoint;
9
+ export declare function subtractFixedPoint(a: FixedPoint, b: FixedPoint): FixedPoint;
10
+ export declare function averageFixedPoint(values: FixedPoint[]): FixedPoint;
11
+ export declare function compareFixedPoint(a: FixedPoint, b: FixedPoint): number;
12
+ export declare function fixedPointToBigInt(value?: FixedPoint): bigint;
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toBigIntValue = exports.ZERO_FIXED_POINT = exports.FIXED_POINT_PATTERN = exports.FIXED_POINT_DECIMALS = void 0;
4
+ exports.toFixedPoint = toFixedPoint;
5
+ exports.fromFixedPoint = fromFixedPoint;
6
+ exports.addFixedPoint = addFixedPoint;
7
+ exports.subtractFixedPoint = subtractFixedPoint;
8
+ exports.averageFixedPoint = averageFixedPoint;
9
+ exports.compareFixedPoint = compareFixedPoint;
10
+ exports.fixedPointToBigInt = fixedPointToBigInt;
11
+ const _pkg_1 = require("#pkg");
12
+ exports.FIXED_POINT_DECIMALS = 9;
13
+ exports.FIXED_POINT_PATTERN = /^-?0x[0-9a-f]+$/i;
14
+ exports.ZERO_FIXED_POINT = '0x0';
15
+ const normalizeHex = (value) => value.startsWith('0x') || value.startsWith('0X') ? value : `0x${value}`;
16
+ const toHexString = (value) => {
17
+ if (value === 0n) {
18
+ return exports.ZERO_FIXED_POINT;
19
+ }
20
+ const isNegative = value < 0n;
21
+ const absValue = isNegative ? -value : value;
22
+ const hexValue = (0, _pkg_1.bigintToHex)(absValue);
23
+ return `${isNegative ? '-' : ''}0x${hexValue}`;
24
+ };
25
+ const toBigIntValue = (value) => {
26
+ if (!value) {
27
+ return 0n;
28
+ }
29
+ const trimmed = value.trim();
30
+ if (trimmed.length === 0) {
31
+ return 0n;
32
+ }
33
+ const isNegative = trimmed.startsWith('-');
34
+ const body = isNegative ? trimmed.slice(1) : trimmed;
35
+ const normalized = normalizeHex(body);
36
+ const bigValue = (0, _pkg_1.hexToBigint)(normalized);
37
+ return isNegative ? -bigValue : bigValue;
38
+ };
39
+ exports.toBigIntValue = toBigIntValue;
40
+ function toFixedPoint(value, decimals = exports.FIXED_POINT_DECIMALS) {
41
+ if (!Number.isFinite(value)) {
42
+ return exports.ZERO_FIXED_POINT;
43
+ }
44
+ const scale = Math.pow(10, decimals);
45
+ const scaled = BigInt(Math.round(value * scale));
46
+ return toHexString(scaled);
47
+ }
48
+ function fromFixedPoint(value, decimals = exports.FIXED_POINT_DECIMALS) {
49
+ const bigValue = (0, exports.toBigIntValue)(value);
50
+ if (bigValue === 0n) {
51
+ return 0;
52
+ }
53
+ const scale = Math.pow(10, decimals);
54
+ return Number(bigValue) / scale;
55
+ }
56
+ function addFixedPoint(a, b) {
57
+ return toHexString((0, exports.toBigIntValue)(a) + (0, exports.toBigIntValue)(b));
58
+ }
59
+ function subtractFixedPoint(a, b) {
60
+ return toHexString((0, exports.toBigIntValue)(a) - (0, exports.toBigIntValue)(b));
61
+ }
62
+ function averageFixedPoint(values) {
63
+ if (values.length === 0) {
64
+ return exports.ZERO_FIXED_POINT;
65
+ }
66
+ const sum = values.reduce((acc, value) => acc + (0, exports.toBigIntValue)(value), 0n);
67
+ return toHexString(sum / BigInt(values.length));
68
+ }
69
+ function compareFixedPoint(a, b) {
70
+ const diff = (0, exports.toBigIntValue)(a) - (0, exports.toBigIntValue)(b);
71
+ if (diff === 0n) {
72
+ return 0;
73
+ }
74
+ return diff > 0n ? 1 : -1;
75
+ }
76
+ function fixedPointToBigInt(value) {
77
+ return (0, exports.toBigIntValue)(value);
78
+ }
79
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/conversion/src/ts/fixedPoint/index.ts"],"names":[],"mappings":";;;AAoCA,oCAUC;AAED,wCAUC;AAED,sCAEC;AAED,gDAEC;AAED,8CAMC;AAED,8CAMC;AAED,gDAEC;AAtFD,+BAAgD;AAInC,QAAA,oBAAoB,GAAG,CAAC,CAAC;AACzB,QAAA,mBAAmB,GAAG,kBAAkB,CAAC;AACzC,QAAA,gBAAgB,GAAe,KAAK,CAAC;AAElD,MAAM,YAAY,GAAG,CAAC,KAAa,EAAU,EAAE,CAC7C,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,KAAK,EAAE,CAAC;AAE1E,MAAM,WAAW,GAAG,CAAC,KAAa,EAAc,EAAE;IAChD,IAAI,KAAK,KAAK,EAAE,EAAE,CAAC;QACjB,OAAO,wBAAgB,CAAC;IAC1B,CAAC;IACD,MAAM,UAAU,GAAG,KAAK,GAAG,EAAE,CAAC;IAC9B,MAAM,QAAQ,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC,KAAK,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,CAAC,CAAC,CAAC;IACjD,IAAI,IAAI,KAAK,EAAE,EAAE,CAAC;QAChB,OAAO,CAAC,CAAC;IACX,CAAC;IACD,OAAO,IAAI,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC5B,CAAC;AAED,SAAgB,kBAAkB,CAAC,KAAkB;IACnD,OAAO,IAAA,qBAAa,EAAC,KAAK,CAAC,CAAC;AAC9B,CAAC"}
@@ -0,0 +1,169 @@
1
+ import { Buffer } from 'buffer';
2
+ export { toFixedPoint, fromFixedPoint, addFixedPoint, subtractFixedPoint, averageFixedPoint, compareFixedPoint, type FixedPoint, FIXED_POINT_DECIMALS, ZERO_FIXED_POINT, fixedPointToBigInt, toBigIntValue, } from './fixedPoint';
3
+ export declare let isNative: boolean;
4
+ /**
5
+ * Convert a little-endian buffer into a BigInt.
6
+ * @param buf The little-endian buffer to convert
7
+ * @returns A BigInt with the little-endian representation of buf.
8
+ */
9
+ export declare function toBigIntLE(buf: Buffer): bigint;
10
+ export declare function validateBigIntBuffer(): boolean;
11
+ /**
12
+ * Convert a big-endian buffer into a BigInt
13
+ * @param buf The big-endian buffer to convert.
14
+ * @returns A BigInt with the big-endian representation of buf.
15
+ */
16
+ export declare function toBigIntBE(buf: Buffer): bigint;
17
+ /**
18
+ * Convert a BigInt to a little-endian buffer.
19
+ * @param num The BigInt to convert.
20
+ * @param width The number of bytes that the resulting buffer should be.
21
+ * @returns A little-endian buffer representation of num.
22
+ */
23
+ export declare function toBufferLE(num: bigint, width: number): Buffer;
24
+ /**
25
+ * Convert a BigInt to a big-endian buffer.
26
+ * @param num The BigInt to convert.
27
+ * @param width The number of bytes that the resulting buffer should be.
28
+ * @returns A big-endian buffer representation of num.
29
+ */
30
+ export declare function toBufferBE(num: bigint, width: number): Buffer;
31
+ export type TypedArray = Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array | BigInt64Array | BigUint64Array;
32
+ /**
33
+ * Parses a hexadecimal string for correctness and returns it with or without
34
+ * '0x' prefix, and/or with the specified byte length
35
+ * @param a - the string with an hexadecimal number to be parsed
36
+ * @param prefix0x - set to true to prefix the output with '0x'
37
+ * @param byteLength - pad the output to have the desired byte length. Notice
38
+ * that the hex length is double the byte length.
39
+ *
40
+ * @returns
41
+ *
42
+ * @throws {@link RangeError} if input string does not hold an hexadecimal number
43
+ * @throws {@link RangeError} if requested byte length is less than the input byte length
44
+ */
45
+ export declare function parseHex(a: string, prefix0x?: boolean, byteLength?: number): string;
46
+ /**
47
+ * Converts an arbitrary-size non-negative bigint to an ArrayBuffer or a Buffer
48
+ * (default for Node.js)
49
+ *
50
+ * @param a
51
+ * @param returnArrayBuffer - In Node.js, it forces the output to be an
52
+ * ArrayBuffer instead of a Buffer.
53
+ *
54
+ * @returns an ArrayBuffer or a Buffer with a binary representation of the input
55
+ * bigint
56
+ *
57
+ * @throws {@link RangeError} if a < 0.
58
+ */
59
+ export declare function bigintToBuf(a: bigint, returnArrayBuffer?: boolean): ArrayBuffer | Buffer;
60
+ /**
61
+ * Converts an ArrayBuffer, TypedArray or Buffer (node.js) to a bigint
62
+ * @param buf
63
+ * @returns a bigint
64
+ */
65
+ export declare function bufToBigint(buf: ArrayBuffer | TypedArray | Buffer): bigint;
66
+ /**
67
+ * Converts a non-negative bigint to a hexadecimal string
68
+ * @param a - a non negative bigint
69
+ * @param prefix0x - set to true to prefix the output with '0x'
70
+ * @param byteLength - pad the output to have the desired byte length. Notice
71
+ * that the hex length is double the byte length.
72
+ *
73
+ * @returns hexadecimal representation of the input bigint
74
+ *
75
+ * @throws {@link RangeError} if a < 0
76
+ */
77
+ export declare function bigintToHex(a: bigint, prefix0x?: boolean, byteLength?: number): string;
78
+ /**
79
+ * Converts a hexadecimal string to a bigint
80
+ *
81
+ * @param hexStr
82
+ *
83
+ * @returns a bigint
84
+ *
85
+ * @throws {@link RangeError} if input string does not hold an hexadecimal number
86
+ */
87
+ export declare function hexToBigint(hexStr: string): bigint;
88
+ /**
89
+ * Converts a non-negative bigint representing a binary array of utf-8 encoded
90
+ * text to a string of utf-8 text
91
+ *
92
+ * @param a - A non-negative bigint representing a binary array of utf-8 encoded
93
+ * text.
94
+ *
95
+ * @returns a string text with utf-8 encoding
96
+ *
97
+ * @throws {@link RangeError} if a < 0.
98
+ */
99
+ export declare function bigintToText(a: bigint): string;
100
+ /**
101
+ * Converts a utf-8 string to a bigint (from its binary representaion)
102
+ *
103
+ * @param text - A string text with utf-8 encoding
104
+ *
105
+ * @returns a bigint representing a binary array of the input utf-8 encoded text
106
+ */
107
+ export declare function textToBigint(text: string): bigint;
108
+ /**
109
+ * Converts an ArrayBuffer, TypedArray or Buffer (in Node.js) containing utf-8
110
+ * encoded text to a string of utf-8 text
111
+ *
112
+ * @param buf - A buffer containing utf-8 encoded text
113
+ *
114
+ * @returns a string text with utf-8 encoding
115
+ */
116
+ export declare function bufToText(buf: ArrayBuffer | TypedArray | Buffer): string;
117
+ /**
118
+ * Converts a string of utf-8 encoded text to an ArrayBuffer or a Buffer
119
+ * (default in Node.js)
120
+ *
121
+ * @param str - A string of text (with utf-8 encoding)
122
+ * @param returnArrayBuffer - When invoked in Node.js, it can force the output
123
+ * to be an ArrayBuffer instead of a Buffer.
124
+ *
125
+ * @returns an ArrayBuffer or a Buffer containing the utf-8 encoded text
126
+ */
127
+ export declare function textToBuf(str: string, returnArrayBuffer?: boolean): ArrayBuffer | Buffer;
128
+ /**
129
+ * Returns the hexadecimal representation of a buffer.
130
+ *
131
+ * @param buf
132
+ * @param prefix0x - set to true to prefix the output with '0x'
133
+ * @param byteLength - pad the output to have the desired byte length. Notice
134
+ * that the hex length is double the byte length.
135
+ *
136
+ * @returns a string with a hexadecimal representation of the input buffer
137
+ */
138
+ export declare function bufToHex(buf: ArrayBuffer | TypedArray | Buffer, prefix0x?: boolean, byteLength?: number): string;
139
+ /**
140
+ * Converts a hexadecimal string to a buffer
141
+ *
142
+ * @param hexStr - A string representing a number with hexadecimal notation
143
+ * @param returnArrayBuffer - In Node.js, it forces the output to be an
144
+ * ArrayBuffer instead of a Buffer.
145
+ *
146
+ * @returns An ArrayBuffer or a Buffer
147
+ *
148
+ * @throws {@link RangeError} if input string does not hold an hexadecimal number
149
+ */
150
+ export declare function hexToBuf(hexStr: string, returnArrayBuffer?: boolean): ArrayBuffer | Buffer;
151
+ /**
152
+ * Converts an arbitrary-size non-negative bigint to a base64 string
153
+ * @param a - a non negative bigint
154
+ * @param urlsafe - if true Base64 URL encoding is used ('+' and '/' are
155
+ * replaced by '-', '_')
156
+ * @param padding - if false, padding (trailing '=') is removed
157
+ * @returns a base64 representation of the input bigint
158
+ *
159
+ * @throws {RangeError}
160
+ * Thrown if a < 0
161
+ */
162
+ export declare function bigintToBase64(a: bigint, urlsafe?: boolean, padding?: boolean): string;
163
+ /**
164
+ * Converts a base64 string to bigint.
165
+ * @param a base64 string. It accepts standard and URL-safe base64 with and
166
+ * without padding
167
+ * @returns a bigint
168
+ */
169
+ export declare function base64ToBigint(a: string): bigint;