@gsknnft/bigint-buffer 1.3.2 → 1.4.2

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 (106) hide show
  1. package/README.md +123 -126
  2. package/build/Release/bigint_buffer.exp +0 -0
  3. package/build/Release/bigint_buffer.iobj +0 -0
  4. package/build/Release/bigint_buffer.ipdb +0 -0
  5. package/build/Release/bigint_buffer.lib +0 -0
  6. package/build/Release/bigint_buffer.node +0 -0
  7. package/build/Release/bigint_buffer.pdb +0 -0
  8. package/build/Release/obj/bigint_buffer/bigint_buffer.node.recipe +11 -0
  9. package/build/Release/obj/bigint_buffer/bigint_buffer.tlog/CL.command.1.tlog +0 -0
  10. package/build/Release/obj/bigint_buffer/bigint_buffer.tlog/CL.read.1.tlog +0 -0
  11. package/build/Release/obj/bigint_buffer/bigint_buffer.tlog/CL.write.1.tlog +0 -0
  12. package/build/Release/obj/bigint_buffer/bigint_buffer.tlog/Cl.items.tlog +2 -0
  13. package/build/Release/obj/bigint_buffer/bigint_buffer.tlog/bigint_buffer.lastbuildstate +2 -0
  14. package/build/Release/obj/bigint_buffer/bigint_buffer.tlog/link.command.1.tlog +0 -0
  15. package/build/Release/obj/bigint_buffer/bigint_buffer.tlog/link.read.1.tlog +0 -0
  16. package/build/Release/obj/bigint_buffer/bigint_buffer.tlog/link.secondary.1.tlog +5 -0
  17. package/build/Release/obj/bigint_buffer/bigint_buffer.tlog/link.write.1.tlog +0 -0
  18. package/build/Release/obj/bigint_buffer/src/bigint-buffer.obj +0 -0
  19. package/build/Release/obj/bigint_buffer/win_delay_load_hook.obj +0 -0
  20. package/build/bigint_buffer.vcxproj +148 -0
  21. package/build/bigint_buffer.vcxproj.filters +67 -0
  22. package/build/binding.sln +19 -0
  23. package/build/config.gypi +522 -0
  24. package/dist/index.cjs +1 -205
  25. package/dist/index.js +347 -202
  26. package/dist/index.umd.js +1 -0
  27. package/dist/tsconfig.tsbuildinfo +1 -0
  28. package/dist/types/bigint-buffer.test.d.ts +1 -0
  29. package/dist/types/conversion/index.d.ts +1 -0
  30. package/dist/types/conversion/src/ts/index.d.ts +168 -0
  31. package/dist/types/conversion/test/bigintToBase64.test.d.ts +1 -0
  32. package/dist/types/conversion/test/bigintToBuf.test.d.ts +1 -0
  33. package/dist/types/conversion/test/bigintToHex.test.d.ts +1 -0
  34. package/dist/types/conversion/test/bigintToText.test.d.ts +1 -0
  35. package/dist/types/conversion/test/bufToBigint.test.d.ts +1 -0
  36. package/dist/types/conversion/test/hexToBigint.test.d.ts +1 -0
  37. package/dist/types/conversion/test/hexToBuf.test.d.ts +1 -0
  38. package/dist/types/conversion/test/parseHex.test.d.ts +1 -0
  39. package/dist/types/conversion/test/setup.test.d.ts +1 -0
  40. package/dist/types/conversion/test/textToBuf.test.d.ts +1 -0
  41. package/dist/types/conversion/vite.config.d.ts +2 -0
  42. package/dist/types/conversion/vitest.config.d.ts +2 -0
  43. package/dist/types/dist/dist/conversion/conversion/index.d.ts +1 -0
  44. package/dist/{index.d.ts → types/dist/dist/index.d.ts} +2 -0
  45. package/dist/types/index.bench.d.ts +1 -0
  46. package/dist/types/index.d.ts +80 -0
  47. package/dist/types/index.spec.d.ts +1 -0
  48. package/package.json +83 -49
  49. package/src/bigint-buffer.test.ts +11 -0
  50. package/src/conversion/.github/workflows/build-and-test.yml +116 -0
  51. package/src/conversion/CODE_OF_CONDUCT.md +134 -0
  52. package/src/conversion/LICENSE +21 -0
  53. package/src/conversion/README.md +48 -0
  54. package/src/conversion/docs/README.md +34 -0
  55. package/src/conversion/docs/functions/base64ToBigint.md +27 -0
  56. package/src/conversion/docs/functions/bigintToBase64.md +43 -0
  57. package/src/conversion/docs/functions/bigintToBuf.md +35 -0
  58. package/src/conversion/docs/functions/bigintToHex.md +43 -0
  59. package/src/conversion/docs/functions/bigintToText.md +31 -0
  60. package/src/conversion/docs/functions/bufToBigint.md +25 -0
  61. package/src/conversion/docs/functions/bufToHex.md +37 -0
  62. package/src/conversion/docs/functions/bufToText.md +27 -0
  63. package/src/conversion/docs/functions/hexToBigint.md +29 -0
  64. package/src/conversion/docs/functions/hexToBuf.md +37 -0
  65. package/src/conversion/docs/functions/parseHex.md +45 -0
  66. package/src/conversion/docs/functions/textToBigint.md +27 -0
  67. package/src/conversion/docs/functions/textToBuf.md +33 -0
  68. package/src/conversion/docs/functions/toBigIntBE.md +27 -0
  69. package/src/conversion/docs/functions/toBigIntLE.md +27 -0
  70. package/src/conversion/docs/functions/toBufferBE.md +33 -0
  71. package/src/conversion/docs/functions/toBufferLE.md +33 -0
  72. package/src/conversion/docs/functions/validateBigIntBuffer.md +15 -0
  73. package/src/conversion/docs/type-aliases/TypedArray.md +11 -0
  74. package/src/conversion/docs/variables/isNative.md +11 -0
  75. package/src/conversion/example.cjs +9 -0
  76. package/src/conversion/example.esm.js +11 -0
  77. package/src/conversion/index.ts +1 -0
  78. package/src/conversion/package.json +163 -0
  79. package/src/conversion/src/docs/index.md +47 -0
  80. package/src/conversion/src/ts/index.ts +514 -0
  81. package/src/conversion/test/bigintToBase64.test.ts +37 -0
  82. package/src/conversion/test/bigintToBuf.test.ts +43 -0
  83. package/src/conversion/test/bigintToHex.test.ts +52 -0
  84. package/src/conversion/test/bigintToText.test.ts +30 -0
  85. package/src/conversion/test/bufToBigint.test.ts +20 -0
  86. package/src/conversion/test/hexToBigint.test.ts +22 -0
  87. package/src/conversion/test/hexToBuf.test.ts +39 -0
  88. package/src/conversion/test/parseHex.test.ts +35 -0
  89. package/src/conversion/test/setup.test.ts +9 -0
  90. package/src/conversion/test/textToBuf.test.ts +26 -0
  91. package/src/conversion/tsconfig.json +57 -0
  92. package/src/conversion/tsconfig.rollup.json +9 -0
  93. package/src/conversion/typedoc.json +5 -0
  94. package/src/conversion/types/bindings.d.t.s +4 -0
  95. package/src/conversion/vite.config.ts +10 -0
  96. package/src/conversion/vitest.config.ts +15 -0
  97. package/src/index.bench.ts +5 -6
  98. package/src/index.spec.ts +232 -358
  99. package/src/index.ts +33 -28
  100. package/.travis.yml +0 -51
  101. package/PR_TEMPLATE.md +0 -53
  102. package/dist/node.js +0 -94
  103. package/karma.conf.js +0 -62
  104. package/rollup.cjs.config.js +0 -8
  105. package/rollup.esm.config.js +0 -15
  106. package/tsconfig.json +0 -20
package/dist/index.js CHANGED
@@ -1,203 +1,348 @@
1
- Object.defineProperty(exports, "__esModule", { value: true });
2
- exports.isNative = void 0;
3
- exports.toBigIntLE = toBigIntLE;
4
- exports.validateBigIntBuffer = validateBigIntBuffer;
5
- exports.toBigIntBE = toBigIntBE;
6
- exports.toBufferLE = toBufferLE;
7
- exports.toBufferBE = toBufferBE;
8
- exports.bigintToBuf = bigintToBuf;
9
- exports.bufToBigint = bufToBigint;
10
- exports.bigintToHex = bigintToHex;
11
- exports.hexToBigint = hexToBigint;
12
- exports.bigintToText = bigintToText;
13
- exports.textToBigint = textToBigint;
14
- exports.bigintToBase64 = bigintToBase64;
15
- exports.base64ToBigint = base64ToBigint;
16
- let converter;
17
- exports.isNative = false;
18
- {
19
- try {
20
- converter = require('bindings')('bigint_buffer');
21
- exports.isNative = !false && converter !== undefined;
22
- }
23
- catch (e) {
24
- console.warn('bigint: Failed to load bindings, pure JS will be used (try npm run rebuild?)');
25
- }
26
- }
27
- /**
28
- * Convert a little-endian buffer into a BigInt.
29
- * @param buf The little-endian buffer to convert
30
- * @returns A BigInt with the little-endian representation of buf.
31
- */
32
- function toBigIntLE(buf) {
33
- if (converter === undefined) {
34
- const reversed = Buffer.from(buf);
35
- reversed.reverse();
36
- const hex = reversed.toString('hex');
37
- if (hex.length === 0) {
38
- return BigInt(0);
39
- }
40
- return BigInt(`0x${hex}`);
41
- }
42
- return converter.toBigInt(buf, false);
43
- }
44
- function validateBigIntBuffer() {
45
- try {
46
- const test = toBigIntLE(Buffer.from([0x01, 0x00]));
47
- return test === BigInt(1);
48
- }
49
- catch {
50
- return false;
51
- }
52
- }
53
- /**
54
- * Convert a big-endian buffer into a BigInt
55
- * @param buf The big-endian buffer to convert.
56
- * @returns A BigInt with the big-endian representation of buf.
57
- */
58
- function toBigIntBE(buf) {
59
- if (converter === undefined) {
60
- const hex = buf.toString('hex');
61
- if (hex.length === 0) {
62
- return BigInt(0);
63
- }
64
- return BigInt(`0x${hex}`);
65
- }
66
- return converter.toBigInt(buf, true);
67
- }
68
- /**
69
- * Convert a BigInt to a little-endian buffer.
70
- * @param num The BigInt to convert.
71
- * @param width The number of bytes that the resulting buffer should be.
72
- * @returns A little-endian buffer representation of num.
73
- */
74
- function toBufferLE(num, width) {
75
- if (converter === undefined) {
76
- const hex = num.toString(16);
77
- const buffer = Buffer.from(hex.padStart(width * 2, '0').slice(0, width * 2), 'hex');
78
- buffer.reverse();
79
- return buffer;
80
- }
81
- // Allocation is done here, since it is slower using napi in C
82
- return converter.fromBigInt(num, Buffer.allocUnsafe(width), false);
83
- }
84
- /**
85
- * Convert a BigInt to a big-endian buffer.
86
- * @param num The BigInt to convert.
87
- * @param width The number of bytes that the resulting buffer should be.
88
- * @returns A big-endian buffer representation of num.
89
- */
90
- function toBufferBE(num, width) {
91
- if (converter === undefined) {
92
- const hex = num.toString(16);
93
- return Buffer.from(hex.padStart(width * 2, '0').slice(0, width * 2), 'hex');
94
- }
95
- return converter.fromBigInt(num, Buffer.allocUnsafe(width), true);
96
- }
97
- // ========== Conversion Utilities ==========
98
- /**
99
- * Convert a bigint to a Buffer with automatic sizing.
100
- * Uses big-endian encoding and calculates the minimum buffer size needed.
101
- * @param num The bigint to convert
102
- * @returns A big-endian Buffer representation
103
- */
104
- function bigintToBuf(num) {
105
- if (num < BigInt(0)) {
106
- throw new Error('bigintToBuf: negative bigint values are not supported');
107
- }
108
- if (num === BigInt(0)) {
109
- return Buffer.from([0]);
110
- }
111
- // Calculate the number of bytes needed
112
- const hex = num.toString(16);
113
- const width = Math.ceil(hex.length / 2);
114
- return toBufferBE(num, width);
115
- }
116
- /**
117
- * Convert a Buffer to a bigint.
118
- * Assumes big-endian encoding.
119
- * @param buf The buffer to convert
120
- * @returns A bigint representation of the buffer
121
- */
122
- function bufToBigint(buf) {
123
- return toBigIntBE(buf);
124
- }
125
- /**
126
- * Convert a bigint to a hexadecimal string.
127
- * @param num The bigint to convert
128
- * @returns A hexadecimal string (without '0x' prefix)
129
- */
130
- function bigintToHex(num) {
131
- if (num < BigInt(0)) {
132
- throw new Error('bigintToHex: negative bigint values are not supported');
133
- }
134
- const hex = num.toString(16);
135
- // Ensure even length for proper byte representation
136
- return hex.length % 2 === 0 ? hex : '0' + hex;
137
- }
138
- /**
139
- * Convert a hexadecimal string to a bigint.
140
- * @param hex The hexadecimal string (with or without '0x' prefix)
141
- * @returns A bigint representation
142
- */
143
- function hexToBigint(hex) {
144
- // Remove '0x' prefix if present
145
- const cleanHex = hex.startsWith('0x') ? hex.slice(2) : hex;
146
- if (cleanHex.length === 0) {
147
- return BigInt(0);
148
- }
149
- return BigInt(`0x${cleanHex}`);
150
- }
151
- /**
152
- * Convert a bigint to a decimal text string.
153
- * @param num The bigint to convert
154
- * @returns A decimal string representation
155
- */
156
- function bigintToText(num) {
157
- return num.toString(10);
158
- }
159
- /**
160
- * Convert a decimal text string to a bigint.
161
- * @param text The decimal string to convert
162
- * @returns A bigint representation
163
- */
164
- function textToBigint(text) {
165
- if (!text?.trim()) {
166
- throw new Error('textToBigint: input string cannot be empty');
167
- }
168
- try {
169
- return BigInt(text);
170
- }
171
- catch (e) {
172
- throw new Error(`textToBigint: invalid decimal string "${text}"`);
173
- }
174
- }
175
- /**
176
- * Convert a bigint to a base64 string.
177
- * @param num The bigint to convert
178
- * @returns A base64 string representation
179
- */
180
- function bigintToBase64(num) {
181
- if (num < BigInt(0)) {
182
- throw new Error('bigintToBase64: negative bigint values are not supported');
183
- }
184
- const buf = bigintToBuf(num);
185
- return buf.toString('base64');
186
- }
187
- /**
188
- * Convert a base64 string to a bigint.
189
- * @param base64 The base64 string to convert
190
- * @returns A bigint representation
191
- */
192
- function base64ToBigint(base64) {
193
- if (!base64?.trim()) {
194
- throw new Error('base64ToBigint: input string cannot be empty');
195
- }
196
- // Trim whitespace and validate base64 format (allows padding)
197
- const cleaned = base64.trim();
198
- if (!/^[A-Za-z0-9+/]+=*$/.test(cleaned)) {
199
- throw new Error('base64ToBigint: invalid base64 string format');
200
- }
201
- const buf = Buffer.from(cleaned, 'base64');
202
- return bufToBigint(buf);
1
+ import { Buffer as o } from "buffer";
2
+ import c from "path";
3
+ import S from "fs";
4
+ let l = !1, f, B;
5
+ const u = typeof globalThis < "u" && typeof globalThis.document < "u", x = [
6
+ // when running from dist/
7
+ c.resolve(__dirname, ".."),
8
+ // when running from build/conversion/src/ts
9
+ c.resolve(__dirname, "../../.."),
10
+ // when running from src/conversion/src/ts
11
+ c.resolve(__dirname, "../../../../")
12
+ ], $ = () => {
13
+ for (const e of x) {
14
+ const t = c.join(e, "build", "Release", "bigint_buffer.node");
15
+ if (S.existsSync(t)) return e;
16
+ }
17
+ return x[0];
18
+ };
19
+ function _() {
20
+ try {
21
+ const e = require("bindings"), t = $();
22
+ return e({
23
+ bindings: "bigint_buffer",
24
+ module_root: t
25
+ });
26
+ } catch (e) {
27
+ B = e;
28
+ return;
29
+ }
203
30
  }
31
+ u || (f = _(), l = f !== void 0, !l && B !== void 0 && process.env?.BIGINT_BUFFER_SILENT_NATIVE_FAIL !== "1" && console.warn(
32
+ "bigint-buffer: Failed to load native bindings; using pure JS fallback. Run npm run rebuild to restore native.",
33
+ B
34
+ ));
35
+ f === void 0 && (f = {
36
+ toBigInt: (e, t = !0) => {
37
+ const n = o.from(e);
38
+ t || n.reverse();
39
+ const r = n.toString("hex");
40
+ return r.length === 0 ? 0n : BigInt(`0x${r}`);
41
+ },
42
+ fromBigInt: (e, t, n = !0) => {
43
+ const r = e.toString(16), i = t.length, g = r.padStart(i * 2, "0").slice(0, i * 2), b = o.from(g, "hex");
44
+ return n || b.reverse(), b.copy(t), t;
45
+ }
46
+ });
47
+ function v(e) {
48
+ if (u || f === void 0) {
49
+ const t = o.from(e);
50
+ t.reverse();
51
+ const n = t.toString("hex");
52
+ return n.length === 0 ? BigInt(0) : BigInt(`0x${n}`);
53
+ }
54
+ return f.toBigInt(e, !1);
55
+ }
56
+ function A() {
57
+ try {
58
+ return v(o.from([1, 0])) === BigInt(1);
59
+ } catch {
60
+ return !1;
61
+ }
62
+ }
63
+ function R(e) {
64
+ if (u || f === void 0) {
65
+ const t = e.toString("hex");
66
+ return t.length === 0 ? BigInt(0) : BigInt(`0x${t}`);
67
+ }
68
+ return f.toBigInt(e, !0);
69
+ }
70
+ function U(e, t) {
71
+ if (u || f === void 0) {
72
+ const n = e.toString(16), r = o.from(
73
+ n.padStart(t * 2, "0").slice(0, t * 2),
74
+ "hex"
75
+ );
76
+ return r.reverse(), r;
77
+ }
78
+ return f.fromBigInt(e, o.allocUnsafe(t), !1);
79
+ }
80
+ function N(e, t) {
81
+ if (u || f === void 0) {
82
+ const n = e.toString(16);
83
+ return o.from(n.padStart(t * 2, "0").slice(0, t * 2), "hex");
84
+ }
85
+ return f.fromBigInt(e, o.allocUnsafe(t), !0);
86
+ }
87
+ function a(e, t = !1, n) {
88
+ const r = e.match(/^(0x)?([\da-fA-F]+)$/);
89
+ if (r == null)
90
+ throw new RangeError(
91
+ "input must be a hexadecimal string, e.g. '0x124fe3a' or '0214f1b2'"
92
+ );
93
+ let i = r[2];
94
+ if (n !== void 0) {
95
+ if (n < i.length / 2)
96
+ throw new RangeError(
97
+ `expected byte length ${n} < input hex byte length ${Math.ceil(
98
+ i.length / 2
99
+ )}`
100
+ );
101
+ i = i.padStart(n * 2, "0");
102
+ }
103
+ return t ? "0x" + i : i;
104
+ }
105
+ function p(e, t = !1) {
106
+ if (e < 0)
107
+ throw RangeError(
108
+ "a should be a non-negative integer. Negative values are not supported"
109
+ );
110
+ return h(m(e), t);
111
+ }
112
+ function T(e) {
113
+ let t = 8n;
114
+ ArrayBuffer.isView(e) ? t = BigInt(e.BYTES_PER_ELEMENT * 8) : e = new Uint8Array(e);
115
+ let n = 0n;
116
+ for (const r of e.values()) {
117
+ const i = BigInt(r);
118
+ n = (n << t) + i;
119
+ }
120
+ return n;
121
+ }
122
+ function m(e, t = !1, n) {
123
+ if (e < 0)
124
+ throw RangeError(
125
+ "a should be a non-negative integer. Negative values are not supported"
126
+ );
127
+ return a(e.toString(16), t, n);
128
+ }
129
+ function w(e) {
130
+ return BigInt(a(e, !0));
131
+ }
132
+ function L(e) {
133
+ if (e < 0)
134
+ throw RangeError(
135
+ "a should be a non-negative integer. Negative values are not supported"
136
+ );
137
+ return I(h(e.toString(16)));
138
+ }
139
+ function O(e) {
140
+ return w(E(y(e)));
141
+ }
142
+ function d(e) {
143
+ if (o.isBuffer(e))
144
+ return e;
145
+ if (ArrayBuffer.isView(e))
146
+ return o.from(e.buffer, e.byteOffset, e.byteLength);
147
+ if (e instanceof ArrayBuffer)
148
+ return o.from(new Uint8Array(e));
149
+ throw new TypeError("Unsupported input type for Buffer.from");
150
+ }
151
+ function I(e) {
152
+ const t = d(e);
153
+ return u ? new TextDecoder().decode(new Uint8Array(t)) : o.from(t).toString();
154
+ }
155
+ function y(e, t = !1) {
156
+ return !u && !t ? o.from(new TextEncoder().encode(e).buffer) : new TextEncoder().encode(e).buffer;
157
+ }
158
+ function E(e, t = !1, n) {
159
+ if (u) {
160
+ let r = "";
161
+ const i = "0123456789abcdef";
162
+ return ArrayBuffer.isView(e) ? e = new Uint8Array(
163
+ e.buffer.slice(e.byteOffset, e.byteOffset + e.byteLength)
164
+ ) : e = new Uint8Array(e), e.forEach((g) => {
165
+ r += i[g >> 4] + i[g & 15];
166
+ }), a(r, t, n);
167
+ } else {
168
+ const r = d(e);
169
+ return ArrayBuffer.isView(r) && (e = new Uint8Array(
170
+ r.buffer.slice(
171
+ r.byteOffset,
172
+ r.byteOffset + r.byteLength
173
+ )
174
+ )), a(
175
+ o.from(d(e)).toString("hex"),
176
+ t,
177
+ n
178
+ );
179
+ }
180
+ }
181
+ function h(e, t = !1) {
182
+ let n = a(e);
183
+ if (n = a(e, !1, Math.ceil(n.length / 2)), u)
184
+ return Uint8Array.from(
185
+ n.match(/[\da-fA-F]{2}/g).map((r) => +("0x" + r))
186
+ ).buffer;
187
+ {
188
+ const r = o.from(n, "hex");
189
+ return t ? r.buffer.slice(r.byteOffset, r.byteOffset + r.byteLength) : r;
190
+ }
191
+ }
192
+ function F(e, t = !1, n = !0) {
193
+ if (e < 0n)
194
+ throw new RangeError("negative bigint");
195
+ const r = p(e);
196
+ let i = o.isBuffer(r) ? r.toString("base64") : o.from(r).toString("base64");
197
+ return t && (i = i.replace(/\+/g, "-").replace(/\//g, "_")), n || (i = i.replace(/=+$/, "")), i;
198
+ }
199
+ function H(e) {
200
+ if (!e || e.trim() === "")
201
+ return 0n;
202
+ const t = e.trim();
203
+ if (!/^[A-Za-z0-9+/=_-]*$/.test(t))
204
+ throw new RangeError("invalid base64");
205
+ let n = t.replace(/-/g, "+").replace(/_/g, "/");
206
+ for (; n.length % 4 !== 0; )
207
+ n += "=";
208
+ const r = o.from(n, "base64");
209
+ return T(r);
210
+ }
211
+ const k = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
212
+ __proto__: null,
213
+ base64ToBigint: H,
214
+ bigintToBase64: F,
215
+ bigintToBuf: p,
216
+ bigintToHex: m,
217
+ bigintToText: L,
218
+ bufToBigint: T,
219
+ bufToHex: E,
220
+ bufToText: I,
221
+ hexToBigint: w,
222
+ hexToBuf: h,
223
+ get isNative() {
224
+ return l;
225
+ },
226
+ parseHex: a,
227
+ textToBigint: O,
228
+ textToBuf: y,
229
+ toBigIntBE: R,
230
+ toBigIntLE: v,
231
+ toBufferBE: N,
232
+ toBufferLE: U,
233
+ validateBigIntBuffer: A
234
+ }, Symbol.toStringTag, { value: "Module" }));
235
+ let s, M = !1;
236
+ if (typeof window > "u")
237
+ try {
238
+ s = require("bindings")("bigint_buffer"), M = s !== void 0;
239
+ } catch (e) {
240
+ console.warn(
241
+ "bigint: Failed to load bindings, pure JS will be used (try npm run rebuild?)",
242
+ e
243
+ );
244
+ }
245
+ function V(e) {
246
+ if (typeof window < "u" || s === void 0) {
247
+ const t = Buffer.from(e);
248
+ t.reverse();
249
+ const n = t.toString("hex");
250
+ return n.length === 0 ? BigInt(0) : BigInt(`0x${n}`);
251
+ }
252
+ return s.toBigInt(e, !1);
253
+ }
254
+ function D() {
255
+ try {
256
+ return V(Buffer.from([1, 0])) === BigInt(1);
257
+ } catch {
258
+ return !1;
259
+ }
260
+ }
261
+ function j(e) {
262
+ if (typeof window < "u" || s === void 0) {
263
+ const t = e.toString("hex");
264
+ return t.length === 0 ? BigInt(0) : BigInt(`0x${t}`);
265
+ }
266
+ return s.toBigInt(e, !0);
267
+ }
268
+ function G(e, t) {
269
+ if (typeof window < "u" || s === void 0) {
270
+ const n = e.toString(16), r = Buffer.from(
271
+ n.padStart(t * 2, "0").slice(0, t * 2),
272
+ "hex"
273
+ );
274
+ return r.reverse(), r;
275
+ }
276
+ return s.fromBigInt(e, Buffer.allocUnsafe(t), !1);
277
+ }
278
+ function z(e, t) {
279
+ if (typeof window < "u" || s === void 0) {
280
+ const n = e.toString(16);
281
+ return Buffer.from(n.padStart(t * 2, "0").slice(0, t * 2), "hex");
282
+ }
283
+ return s.fromBigInt(e, Buffer.allocUnsafe(t), !0);
284
+ }
285
+ function q(e) {
286
+ if (e < BigInt(0))
287
+ throw new Error("bigintToBuf: negative bigint values are not supported");
288
+ if (e === BigInt(0))
289
+ return Buffer.from([0]);
290
+ const t = e.toString(16), n = Math.ceil(t.length / 2);
291
+ return z(e, n);
292
+ }
293
+ function J(e) {
294
+ return j(e);
295
+ }
296
+ function Y(e) {
297
+ if (e < BigInt(0))
298
+ throw new Error("bigintToHex: negative bigint values are not supported");
299
+ const t = e.toString(16);
300
+ return t.length % 2 === 0 ? t : "0" + t;
301
+ }
302
+ function C(e) {
303
+ const t = e.startsWith("0x") ? e.slice(2) : e;
304
+ return t.length === 0 ? BigInt(0) : BigInt(`0x${t}`);
305
+ }
306
+ function K(e) {
307
+ return e.toString(10);
308
+ }
309
+ function Q(e) {
310
+ if (!e?.trim())
311
+ throw new Error("textToBigint: input string cannot be empty");
312
+ try {
313
+ return BigInt(e);
314
+ } catch (t) {
315
+ throw new Error(`textToBigint: invalid decimal string "${e}" ${t instanceof Error ? t.message : String(t)}`);
316
+ }
317
+ }
318
+ function X(e) {
319
+ if (e < BigInt(0))
320
+ throw new Error("bigintToBase64: negative bigint values are not supported");
321
+ return q(e).toString("base64");
322
+ }
323
+ function ee(e) {
324
+ if (!e?.trim())
325
+ throw new Error("base64ToBigint: input string cannot be empty");
326
+ const t = e.trim();
327
+ if (!/^[A-Za-z0-9+/]+=*$/.test(t))
328
+ throw new Error("base64ToBigint: invalid base64 string format");
329
+ const n = Buffer.from(t, "base64");
330
+ return J(n);
331
+ }
332
+ export {
333
+ ee as base64ToBigint,
334
+ X as bigintToBase64,
335
+ q as bigintToBuf,
336
+ Y as bigintToHex,
337
+ K as bigintToText,
338
+ J as bufToBigint,
339
+ k as conversionUtils,
340
+ C as hexToBigint,
341
+ M as isNative,
342
+ Q as textToBigint,
343
+ j as toBigIntBE,
344
+ V as toBigIntLE,
345
+ z as toBufferBE,
346
+ G as toBufferLE,
347
+ D as validateBigIntBuffer
348
+ };
@@ -0,0 +1 @@
1
+ (function(i,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("buffer"),require("path"),require("fs")):typeof define=="function"&&define.amd?define(["exports","buffer","path","fs"],o):(i=typeof globalThis<"u"?globalThis:i||self,o(i["bigint-buffer"]={},i.buffer,i.path,i.fs))})(this,(function(i,o,c,N){"use strict";let l=!1,u,d;const a=typeof globalThis<"u"&&typeof globalThis.document<"u",T=[c.resolve(__dirname,".."),c.resolve(__dirname,"../../.."),c.resolve(__dirname,"../../../../")],L=()=>{for(const e of T){const t=c.join(e,"build","Release","bigint_buffer.node");if(N.existsSync(t))return e}return T[0]};function O(){try{const e=require("bindings"),t=L();return e({bindings:"bigint_buffer",module_root:t})}catch(e){d=e;return}}a||(u=O(),l=u!==void 0,!l&&d!==void 0&&process.env?.BIGINT_BUFFER_SILENT_NATIVE_FAIL!=="1"&&console.warn("bigint-buffer: Failed to load native bindings; using pure JS fallback. Run npm run rebuild to restore native.",d)),u===void 0&&(u={toBigInt:(e,t=!0)=>{const n=o.Buffer.from(e);t||n.reverse();const r=n.toString("hex");return r.length===0?0n:BigInt(`0x${r}`)},fromBigInt:(e,t,n=!0)=>{const r=e.toString(16),f=t.length,B=r.padStart(f*2,"0").slice(0,f*2),U=o.Buffer.from(B,"hex");return n||U.reverse(),U.copy(t),t}});function v(e){if(a||u===void 0){const t=o.Buffer.from(e);t.reverse();const n=t.toString("hex");return n.length===0?BigInt(0):BigInt(`0x${n}`)}return u.toBigInt(e,!1)}function H(){try{return v(o.Buffer.from([1,0]))===BigInt(1)}catch{return!1}}function M(e){if(a||u===void 0){const t=e.toString("hex");return t.length===0?BigInt(0):BigInt(`0x${t}`)}return u.toBigInt(e,!0)}function F(e,t){if(a||u===void 0){const n=e.toString(16),r=o.Buffer.from(n.padStart(t*2,"0").slice(0,t*2),"hex");return r.reverse(),r}return u.fromBigInt(e,o.Buffer.allocUnsafe(t),!1)}function j(e,t){if(a||u===void 0){const n=e.toString(16);return o.Buffer.from(n.padStart(t*2,"0").slice(0,t*2),"hex")}return u.fromBigInt(e,o.Buffer.allocUnsafe(t),!0)}function g(e,t=!1,n){const r=e.match(/^(0x)?([\da-fA-F]+)$/);if(r==null)throw new RangeError("input must be a hexadecimal string, e.g. '0x124fe3a' or '0214f1b2'");let f=r[2];if(n!==void 0){if(n<f.length/2)throw new RangeError(`expected byte length ${n} < input hex byte length ${Math.ceil(f.length/2)}`);f=f.padStart(n*2,"0")}return t?"0x"+f:f}function x(e,t=!1){if(e<0)throw RangeError("a should be a non-negative integer. Negative values are not supported");return b(w(e),t)}function I(e){let t=8n;ArrayBuffer.isView(e)?t=BigInt(e.BYTES_PER_ELEMENT*8):e=new Uint8Array(e);let n=0n;for(const r of e.values()){const f=BigInt(r);n=(n<<t)+f}return n}function w(e,t=!1,n){if(e<0)throw RangeError("a should be a non-negative integer. Negative values are not supported");return g(e.toString(16),t,n)}function m(e){return BigInt(g(e,!0))}function q(e){if(e<0)throw RangeError("a should be a non-negative integer. Negative values are not supported");return y(b(e.toString(16)))}function V(e){return m(p(E(e)))}function h(e){if(o.Buffer.isBuffer(e))return e;if(ArrayBuffer.isView(e))return o.Buffer.from(e.buffer,e.byteOffset,e.byteLength);if(e instanceof ArrayBuffer)return o.Buffer.from(new Uint8Array(e));throw new TypeError("Unsupported input type for Buffer.from")}function y(e){const t=h(e);return a?new TextDecoder().decode(new Uint8Array(t)):o.Buffer.from(t).toString()}function E(e,t=!1){return!a&&!t?o.Buffer.from(new TextEncoder().encode(e).buffer):new TextEncoder().encode(e).buffer}function p(e,t=!1,n){if(a){let r="";const f="0123456789abcdef";return ArrayBuffer.isView(e)?e=new Uint8Array(e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength)):e=new Uint8Array(e),e.forEach(B=>{r+=f[B>>4]+f[B&15]}),g(r,t,n)}else{const r=h(e);return ArrayBuffer.isView(r)&&(e=new Uint8Array(r.buffer.slice(r.byteOffset,r.byteOffset+r.byteLength))),g(o.Buffer.from(h(e)).toString("hex"),t,n)}}function b(e,t=!1){let n=g(e);if(n=g(e,!1,Math.ceil(n.length/2)),a)return Uint8Array.from(n.match(/[\da-fA-F]{2}/g).map(r=>+("0x"+r))).buffer;{const r=o.Buffer.from(n,"hex");return t?r.buffer.slice(r.byteOffset,r.byteOffset+r.byteLength):r}}function z(e,t=!1,n=!0){if(e<0n)throw new RangeError("negative bigint");const r=x(e);let f=o.Buffer.isBuffer(r)?r.toString("base64"):o.Buffer.from(r).toString("base64");return t&&(f=f.replace(/\+/g,"-").replace(/\//g,"_")),n||(f=f.replace(/=+$/,"")),f}function P(e){if(!e||e.trim()==="")return 0n;const t=e.trim();if(!/^[A-Za-z0-9+/=_-]*$/.test(t))throw new RangeError("invalid base64");let n=t.replace(/-/g,"+").replace(/_/g,"/");for(;n.length%4!==0;)n+="=";const r=o.Buffer.from(n,"base64");return I(r)}const J=Object.freeze(Object.defineProperty({__proto__:null,base64ToBigint:P,bigintToBase64:z,bigintToBuf:x,bigintToHex:w,bigintToText:q,bufToBigint:I,bufToHex:p,bufToText:y,hexToBigint:m,hexToBuf:b,get isNative(){return l},parseHex:g,textToBigint:V,textToBuf:E,toBigIntBE:M,toBigIntLE:v,toBufferBE:j,toBufferLE:F,validateBigIntBuffer:H},Symbol.toStringTag,{value:"Module"}));let s;if(i.isNative=!1,typeof window>"u")try{s=require("bindings")("bigint_buffer"),i.isNative=s!==void 0}catch(e){console.warn("bigint: Failed to load bindings, pure JS will be used (try npm run rebuild?)",e)}function S(e){if(typeof window<"u"||s===void 0){const t=Buffer.from(e);t.reverse();const n=t.toString("hex");return n.length===0?BigInt(0):BigInt(`0x${n}`)}return s.toBigInt(e,!1)}function W(){try{return S(Buffer.from([1,0]))===BigInt(1)}catch{return!1}}function $(e){if(typeof window<"u"||s===void 0){const t=e.toString("hex");return t.length===0?BigInt(0):BigInt(`0x${t}`)}return s.toBigInt(e,!0)}function Z(e,t){if(typeof window<"u"||s===void 0){const n=e.toString(16),r=Buffer.from(n.padStart(t*2,"0").slice(0,t*2),"hex");return r.reverse(),r}return s.fromBigInt(e,Buffer.allocUnsafe(t),!1)}function _(e,t){if(typeof window<"u"||s===void 0){const n=e.toString(16);return Buffer.from(n.padStart(t*2,"0").slice(0,t*2),"hex")}return s.fromBigInt(e,Buffer.allocUnsafe(t),!0)}function A(e){if(e<BigInt(0))throw new Error("bigintToBuf: negative bigint values are not supported");if(e===BigInt(0))return Buffer.from([0]);const t=e.toString(16),n=Math.ceil(t.length/2);return _(e,n)}function R(e){return $(e)}function k(e){if(e<BigInt(0))throw new Error("bigintToHex: negative bigint values are not supported");const t=e.toString(16);return t.length%2===0?t:"0"+t}function D(e){const t=e.startsWith("0x")?e.slice(2):e;return t.length===0?BigInt(0):BigInt(`0x${t}`)}function G(e){return e.toString(10)}function Y(e){if(!e?.trim())throw new Error("textToBigint: input string cannot be empty");try{return BigInt(e)}catch(t){throw new Error(`textToBigint: invalid decimal string "${e}" ${t instanceof Error?t.message:String(t)}`)}}function C(e){if(e<BigInt(0))throw new Error("bigintToBase64: negative bigint values are not supported");return A(e).toString("base64")}function K(e){if(!e?.trim())throw new Error("base64ToBigint: input string cannot be empty");const t=e.trim();if(!/^[A-Za-z0-9+/]+=*$/.test(t))throw new Error("base64ToBigint: invalid base64 string format");const n=Buffer.from(t,"base64");return R(n)}i.base64ToBigint=K,i.bigintToBase64=C,i.bigintToBuf=A,i.bigintToHex=k,i.bigintToText=G,i.bufToBigint=R,i.conversionUtils=J,i.hexToBigint=D,i.textToBigint=Y,i.toBigIntBE=$,i.toBigIntLE=S,i.toBufferBE=_,i.toBufferLE=Z,i.validateBigIntBuffer=W,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})}));