@gsknnft/bigint-buffer 1.4.7 → 1.5.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.
Files changed (46) hide show
  1. package/README.md +150 -144
  2. package/dist/build/Release/bigint_buffer.node +0 -0
  3. package/dist/conversion/bundle.iife.js +421 -0
  4. package/dist/conversion/bundle.umd.js +423 -0
  5. package/dist/conversion/cjs/converter.d.ts +14 -0
  6. package/dist/conversion/cjs/index.d.ts +33 -0
  7. package/dist/conversion/cjs/index.js +418 -0
  8. package/dist/conversion/cjs/index.node.js +4 -0
  9. package/dist/conversion/cjs/package.json +1 -0
  10. package/dist/conversion/converter.d.ts +14 -0
  11. package/dist/conversion/esm/bundle.js +416 -0
  12. package/dist/conversion/esm/bundle.min.js +1 -0
  13. package/dist/conversion/esm/converter.d.ts +14 -0
  14. package/dist/conversion/esm/index.browser.js +416 -0
  15. package/dist/conversion/esm/index.d.ts +33 -0
  16. package/dist/conversion/esm/index.js +416 -0
  17. package/dist/conversion/esm/index.node.js +2 -0
  18. package/dist/conversion/esm/package.json +1 -0
  19. package/dist/conversion/index.d.ts +1 -2
  20. package/dist/index.cjs +1 -1
  21. package/dist/index.d.ts +4 -3
  22. package/dist/index.js +190 -250
  23. package/dist/index.umd.js +1 -1
  24. package/dist/types/conversion/index.d.ts +1 -2
  25. package/dist/types/conversion/src/index.d.ts +2 -0
  26. package/dist/types/conversion/src/ts/index.d.ts +4 -2
  27. package/dist/types/index.d.ts +4 -3
  28. package/package.json +141 -136
  29. package/scripts/postinstall.cjs +5 -3
  30. package/dist/tsconfig.tsbuildinfo +0 -1
  31. package/dist/types/bigint-buffer.test.d.ts +0 -1
  32. package/dist/types/conversion/test/bigintToBase64.test.d.ts +0 -1
  33. package/dist/types/conversion/test/bigintToBuf.test.d.ts +0 -1
  34. package/dist/types/conversion/test/bigintToHex.test.d.ts +0 -1
  35. package/dist/types/conversion/test/bigintToText.test.d.ts +0 -1
  36. package/dist/types/conversion/test/bufToBigint.test.d.ts +0 -1
  37. package/dist/types/conversion/test/fixedPoint.test.d.ts +0 -1
  38. package/dist/types/conversion/test/hexToBigint.test.d.ts +0 -1
  39. package/dist/types/conversion/test/hexToBuf.test.d.ts +0 -1
  40. package/dist/types/conversion/test/parseHex.test.d.ts +0 -1
  41. package/dist/types/conversion/test/setup.test.d.ts +0 -1
  42. package/dist/types/conversion/test/textToBuf.test.d.ts +0 -1
  43. package/dist/types/conversion/vite.config.d.ts +0 -2
  44. package/dist/types/conversion/vitest.config.d.ts +0 -2
  45. package/dist/types/index.bench.d.ts +0 -1
  46. package/dist/types/index.spec.d.ts +0 -1
package/dist/index.js CHANGED
@@ -1,39 +1,84 @@
1
- let v = !1, g, B;
2
- const h = typeof globalThis < "u" && typeof globalThis.document < "u";
3
- let s, b;
4
- typeof process < "u" && process.versions?.node && !h && (s = require("path"), b = require("fs"));
5
- const I = () => {
6
- if (s)
7
- try {
8
- const t = require.resolve("@gsknnft/bigint-buffer/package.json");
9
- return s.dirname(t);
10
- } catch {
11
- return;
12
- }
13
- }, T = () => {
14
- if (!s) return [];
15
- const t = /* @__PURE__ */ new Set(), n = (o) => {
16
- if (!o) return;
17
- const i = s.resolve(o);
18
- t.has(i) || t.add(i);
19
- }, e = I(), r = typeof process < "u" && process.resourcesPath;
20
- return n(process.env?.BIGINT_BUFFER_NATIVE_PATH), n(e), n(e ? s.join(e, "dist") : void 0), n(
21
- r ? s.join(
1
+ import { createRequire as v } from "node:module";
2
+ import { fileURLToPath as T } from "node:url";
3
+ import { dirname as _ } from "node:path";
4
+ const a = v(import.meta.url), x = T(import.meta.url), c = _(x);
5
+ let d;
6
+ const b = typeof globalThis < "u" && typeof globalThis.document < "u";
7
+ let f, g;
8
+ typeof process < "u" && process.versions?.node && !b && (f = a("path"), g = a("fs"));
9
+ const p = () => {
10
+ if (!f || !g) return;
11
+ let t = c;
12
+ for (; ; ) {
13
+ const i = f.join(
14
+ t,
15
+ "node_modules",
16
+ "@gsknnft",
17
+ "bigint-buffer",
18
+ "package.json"
19
+ );
20
+ if (g.existsSync(i))
21
+ return f.dirname(i);
22
+ const s = f.dirname(t);
23
+ if (s === t) break;
24
+ t = s;
25
+ }
26
+ const n = typeof a == "function" && typeof a.resolve == "function", e = (i) => {
27
+ if (n)
28
+ try {
29
+ return a.resolve(i);
30
+ } catch {
31
+ return;
32
+ }
33
+ }, r = e("@gsknnft/bigint-buffer") ?? e("@gsknnft/bigint-buffer/dist/index.cjs") ?? e("@gsknnft/bigint-buffer/dist/index.js");
34
+ let o = r ? f.dirname(r) : c;
35
+ for (; ; ) {
36
+ const i = f.join(o, "package.json");
37
+ if (g.existsSync(i))
38
+ return o;
39
+ const s = f.dirname(o);
40
+ if (s === o) break;
41
+ o = s;
42
+ }
43
+ }, w = () => {
44
+ if (!f) return [];
45
+ const t = /* @__PURE__ */ new Set(), n = (i) => {
46
+ if (!i) return;
47
+ const s = f.resolve(i);
48
+ t.has(s) || t.add(s);
49
+ }, e = p(), r = typeof process < "u" && process.resourcesPath;
50
+ n(process.env?.BIGINT_BUFFER_NATIVE_PATH), n(e), n(e ? f.join(e, "dist") : void 0), n(
51
+ r ? f.join(
22
52
  r,
23
53
  "app.asar.unpacked",
24
54
  "node_modules",
25
55
  "@gsknnft",
26
56
  "bigint-buffer"
27
57
  ) : void 0
28
- ), n(s.resolve(__dirname, "..")), n(s.resolve(__dirname, "../..")), n(s.resolve(__dirname, "../../..")), n(s.resolve(__dirname, "../../../..")), n(s.resolve(__dirname, "../../../../..")), Array.from(t);
29
- }, w = () => {
30
- if (!(!s || !b))
31
- for (const t of T()) {
32
- const n = s.join(t, "build", "Release", "bigint_buffer.node");
33
- if (b.existsSync(n))
34
- return t;
58
+ ), n(f.resolve(c, "..")), n(f.resolve(c, "../..")), n(f.resolve(c, "../../..")), n(f.resolve(c, "../../../..")), n(f.resolve(c, "../../../../.."));
59
+ const o = Array.from(t);
60
+ return process.env.BIGINT_BUFFER_DEBUG && console.log("bigint-buffer: candidateRoots:", o), o;
61
+ }, R = () => {
62
+ if (!(!f || !g)) {
63
+ for (const t of w()) {
64
+ const n = f.join(t, "build", "Release", "bigint_buffer.node");
65
+ if (process.env.BIGINT_BUFFER_DEBUG && console.log("bigint-buffer: checking for native at", n), g.existsSync(n))
66
+ return process.env.BIGINT_BUFFER_DEBUG && console.log("bigint-buffer: found native at", n), t;
67
+ const e = f.join(
68
+ t,
69
+ "dist",
70
+ "build",
71
+ "Release",
72
+ "bigint_buffer.node"
73
+ );
74
+ if (process.env.BIGINT_BUFFER_DEBUG && console.log("bigint-buffer: checking for native at", e), g.existsSync(e))
75
+ return process.env.BIGINT_BUFFER_DEBUG && console.log("bigint-buffer: found native at", e), f.join(t, "dist");
35
76
  }
36
- }, N = (t) => {
77
+ process.env.BIGINT_BUFFER_DEBUG && console.warn(
78
+ "bigint-buffer: native binary not found in any candidate root"
79
+ );
80
+ }
81
+ }, F = (t) => {
37
82
  if (typeof t == "function")
38
83
  return t;
39
84
  if (t && typeof t == "object") {
@@ -44,48 +89,39 @@ const I = () => {
44
89
  return n.default;
45
90
  }
46
91
  throw new TypeError("bindings is not a function");
47
- }, R = () => {
48
- if (s)
92
+ }, N = () => {
93
+ if (f)
49
94
  try {
50
- const t = require("node-gyp-build"), n = I();
95
+ const t = a("node-gyp-build"), n = p();
51
96
  return n ? t(n) : void 0;
52
97
  } catch (t) {
53
- B = t;
98
+ d = t;
54
99
  return;
55
100
  }
56
101
  };
57
- function E() {
58
- const t = R();
102
+ function I() {
103
+ d = void 0;
104
+ const t = N();
59
105
  if (t) return t;
60
106
  try {
61
- const n = require("bindings"), e = N(n), r = w();
62
- return e(r ? {
107
+ const n = a("bindings"), e = F(n), r = p(), o = R() ?? r;
108
+ return e(o ? {
63
109
  bindings: "bigint_buffer",
64
- module_root: r
110
+ module_root: o
65
111
  } : "bigint_buffer");
66
112
  } catch (n) {
67
- B = n;
68
- return;
113
+ d = n, process.env?.BIGINT_BUFFER_SILENT_NATIVE_FAIL !== "1" && console.warn(
114
+ "bigint-buffer: Failed to load native bindings; using pure JS fallback. Run npm run rebuild to restore native.",
115
+ d
116
+ );
69
117
  }
70
118
  }
71
- h || (g = E(), v = g !== void 0, !v && B !== void 0 && process.env?.BIGINT_BUFFER_SILENT_NATIVE_FAIL !== "1" && console.warn(
72
- "bigint-buffer: Failed to load native bindings; using pure JS fallback. Run npm run rebuild to restore native.",
73
- B
74
- ));
75
- g === void 0 && (g = {
76
- toBigInt: (t, n = !0) => {
77
- const e = Buffer.from(t);
78
- n || e.reverse();
79
- const r = e.toString("hex");
80
- return r.length === 0 ? 0n : BigInt(`0x${r}`);
81
- },
82
- fromBigInt: (t, n, e = !0) => {
83
- const r = t.toString(16), o = n.length, i = r.padStart(o * 2, "0").slice(0, o * 2), u = Buffer.from(i, "hex");
84
- return e || u.reverse(), u.copy(n), n;
85
- }
86
- });
87
- h || E();
88
- function y(t, n = !1, e) {
119
+ Buffer.prototype.readBigUInt64LE;
120
+ Buffer.prototype.readBigUInt64BE;
121
+ Buffer.prototype.writeBigUInt64LE;
122
+ Buffer.prototype.writeBigUInt64BE;
123
+ b || I();
124
+ function h(t, n = !1, e) {
89
125
  const r = t.match(/^(0x)?([\da-fA-F]+)$/);
90
126
  if (r == null)
91
127
  throw new RangeError(
@@ -94,79 +130,79 @@ function y(t, n = !1, e) {
94
130
  let o = r[2];
95
131
  return n ? "0x" + o : o;
96
132
  }
97
- function F(t, n = !1, e) {
133
+ function U(t, n = !1, e) {
98
134
  if (t < 0)
99
135
  throw RangeError(
100
136
  "a should be a non-negative integer. Negative values are not supported"
101
137
  );
102
- return y(t.toString(16), n);
138
+ return h(t.toString(16), n);
103
139
  }
104
- function $(t) {
105
- return BigInt(y(t, !0));
140
+ function L(t) {
141
+ return BigInt(h(t, !0));
106
142
  }
107
- const L = 9, ot = /^-?0x[0-9a-f]+$/i, m = "0x0", S = (t) => t.startsWith("0x") || t.startsWith("0X") ? t : `0x${t}`, p = (t) => {
143
+ const k = 9, rt = /^-?0x[0-9a-f]+$/i, m = "0x0", P = (t) => t.startsWith("0x") || t.startsWith("0X") ? t : `0x${t}`, B = (t) => {
108
144
  if (t === 0n)
109
145
  return m;
110
- const n = t < 0n, e = n ? -t : t, r = F(e);
146
+ const n = t < 0n, e = n ? -t : t, r = U(e);
111
147
  return `${n ? "-" : ""}0x${r}`;
112
- }, c = (t) => {
148
+ }, u = (t) => {
113
149
  if (!t)
114
150
  return 0n;
115
151
  const n = t.trim();
116
152
  if (n.length === 0)
117
153
  return 0n;
118
- const e = n.startsWith("-"), r = e ? n.slice(1) : n, o = S(r), i = $(o);
154
+ const e = n.startsWith("-"), r = e ? n.slice(1) : n, o = P(r), i = L(o);
119
155
  return e ? -i : i;
120
156
  };
121
- function it(t, n = L) {
157
+ function ot(t, n = k) {
122
158
  if (!Number.isFinite(t))
123
159
  return m;
124
160
  const e = 10n ** BigInt(n), r = BigInt(Math.round(t * Number(e)));
125
- return p(r);
161
+ return B(r);
126
162
  }
127
- function ft(t, n = 9) {
163
+ function it(t, n = 9) {
128
164
  if (!t) return 0;
129
165
  const e = t.trim();
130
166
  if (e.length === 0) return 0;
131
- const r = e.startsWith("-"), o = r ? e.slice(1) : e, i = r ? -BigInt(o) : BigInt(o), u = 10 ** n;
132
- return Number(i) / u;
167
+ const r = e.startsWith("-"), o = r ? e.slice(1) : e, i = r ? -BigInt(o) : BigInt(o), s = 10 ** n;
168
+ return Number(i) / s;
133
169
  }
134
- function st(t, n) {
135
- return p(c(t) + c(n));
170
+ function ft(t, n) {
171
+ return B(u(t) + u(n));
136
172
  }
137
- function ut(t, n) {
138
- return p(c(t) - c(n));
173
+ function st(t, n) {
174
+ return B(u(t) - u(n));
139
175
  }
140
- function ct(t) {
176
+ function ut(t) {
141
177
  if (t.length === 0)
142
178
  return m;
143
- const n = t.reduce((e, r) => e + c(r), 0n);
144
- return p(n / BigInt(t.length));
179
+ const n = t.reduce((e, r) => e + u(r), 0n);
180
+ return B(n / BigInt(t.length));
145
181
  }
146
- function at(t, n) {
147
- const e = c(t) - c(n);
182
+ function ct(t, n) {
183
+ const e = u(t) - u(n);
148
184
  return e === 0n ? 0 : e > 0n ? 1 : -1;
149
185
  }
150
- function dt(t) {
151
- return c(t);
186
+ function at(t) {
187
+ return u(t);
152
188
  }
153
- const P = typeof Buffer.prototype.readBigUInt64LE == "function", k = typeof Buffer.prototype.readBigUInt64BE == "function", j = typeof Buffer.prototype.writeBigUInt64LE == "function", U = typeof Buffer.prototype.writeBigUInt64BE == "function", A = P ? (t, n) => t.readBigUInt64LE(n) : (t, n) => {
189
+ const G = typeof Buffer.prototype.readBigUInt64LE == "function", S = typeof Buffer.prototype.readBigUInt64BE == "function", j = typeof Buffer.prototype.writeBigUInt64LE == "function", D = typeof Buffer.prototype.writeBigUInt64BE == "function", $ = G ? (t, n) => t.readBigUInt64LE(n) : (t, n) => {
154
190
  let e = 0n;
155
191
  for (let r = 7; r >= 0; r--)
156
192
  e = (e << 8n) + BigInt(t[n + r]);
157
193
  return e;
158
- }, W = k ? (t, n) => t.readBigUInt64BE(n) : (t, n) => {
194
+ }, A = S ? (t, n) => t.readBigUInt64BE(n) : (t, n) => {
159
195
  let e = 0n;
160
196
  for (let r = 0; r < 8; r++)
161
197
  e = (e << 8n) + BigInt(t[n + r]);
162
198
  return e;
163
- }, q = j ? (t, n, e) => {
199
+ }, W = j ? (t, n, e) => {
164
200
  t.writeBigUInt64LE(e, n);
165
201
  } : (t, n, e) => {
166
202
  let r = e;
167
203
  for (let o = 0; o < 8; o++)
168
204
  t[n + o] = Number(r & 0xffn), r >>= 8n;
169
- }, H = U ? (t, n, e) => {
205
+ }, H = D ? (t, n, e) => {
170
206
  t.writeBigUInt64BE(e, n);
171
207
  } : (t, n, e) => {
172
208
  let r = e;
@@ -178,11 +214,11 @@ const P = typeof Buffer.prototype.readBigUInt64LE == "function", k = typeof Buff
178
214
  for (let i = 0; i < o; i++)
179
215
  n += BigInt(t[i]) * e, e <<= 8n;
180
216
  for (let i = o; i < r; i += 8) {
181
- const u = A(t, i);
182
- n += u * e, e <<= 64n;
217
+ const s = $(t, i);
218
+ n += s * e, e <<= 64n;
183
219
  }
184
220
  return n;
185
- }, G = (t) => {
221
+ }, O = (t) => {
186
222
  const n = t.length;
187
223
  if (n === 0) return 0n;
188
224
  let e = 0n;
@@ -192,175 +228,94 @@ const P = typeof Buffer.prototype.readBigUInt64LE == "function", k = typeof Buff
192
228
  for (; o < r; o++)
193
229
  e = (e << 8n) + BigInt(t[o]);
194
230
  for (; o < n; o += 8) {
195
- const i = W(t, o);
231
+ const i = A(t, o);
196
232
  e = (e << 64n) + i;
197
233
  }
198
234
  return e;
199
- }, D = (t, n) => {
235
+ }, z = (t, n) => {
200
236
  const e = n.length;
201
237
  let r = t, o = 0;
202
238
  const i = e - e % 8;
203
239
  for (; o < i; o += 8)
204
- q(n, o, r & 0xffffffffffffffffn), r >>= 64n;
240
+ W(n, o, r & 0xffffffffffffffffn), r >>= 64n;
205
241
  for (; o < e; o++)
206
242
  n[o] = Number(r & 0xffn), r >>= 8n;
207
243
  return n;
208
- }, O = (t, n) => {
244
+ }, C = (t, n) => {
209
245
  const e = n.length;
210
246
  let r = t, o = e;
211
247
  const i = e & -8;
212
248
  for (; o > i; )
213
249
  o--, n[o] = Number(r & 0xffn), r >>= 8n;
214
250
  for (; o > 0; o -= 8) {
215
- const u = r & 0xffffffffffffffffn;
216
- H(n, o - 8, u), r >>= 64n;
251
+ const s = r & 0xffffffffffffffffn;
252
+ H(n, o - 8, s), r >>= 64n;
217
253
  }
218
254
  return n;
219
- }, C = (t) => {
255
+ }, M = (t) => {
220
256
  if (t === 0n) return 1;
221
257
  let n = t, e = 0;
222
258
  for (; n > 0n; )
223
259
  e++, n >>= 8n;
224
260
  return e;
225
- }, M = {
226
- toBigInt: (t, n = !0) => n ? G(t) : V(t),
227
- fromBigInt: (t, n, e = !0) => e ? O(t, n) : D(t, n)
228
- }, _ = typeof globalThis < "u" && typeof globalThis.document < "u";
229
- let f, a;
230
- _ || (f = require("path"), a = require("fs"));
231
- const z = () => {
232
- if (!f) return [];
233
- const t = x(), n = typeof process < "u" && process.resourcesPath;
234
- return [
235
- process.env?.BIGINT_BUFFER_NATIVE_PATH,
236
- t,
237
- t ? f.join(t, "dist") : void 0,
238
- n ? f.join(
239
- n,
240
- "app.asar.unpacked",
241
- "node_modules",
242
- "@gsknnft",
243
- "bigint-buffer"
244
- ) : void 0,
245
- f.resolve(__dirname, ".."),
246
- f.resolve(__dirname, "."),
247
- f.resolve(__dirname, "../.."),
248
- f.resolve(__dirname, "../../.."),
249
- f.resolve(__dirname, "../../../..")
250
- ].filter((e) => !!e);
251
- }, X = () => {
252
- if (!(!f || !a))
253
- for (const t of z()) {
254
- const n = f.join(
255
- t,
256
- "build",
257
- "Release",
258
- "bigint_buffer.node"
259
- );
260
- if (a.existsSync(n))
261
- return t;
262
- const e = f.join(
263
- t,
264
- "dist",
265
- "build",
266
- "Release",
267
- "bigint_buffer.node"
268
- );
269
- if (a.existsSync(e))
270
- return f.join(t, "dist");
271
- }
272
- }, J = () => {
273
- if (f)
274
- try {
275
- const t = require("node-gyp-build"), n = x();
276
- return n ? t(n) : void 0;
277
- } catch (t) {
278
- d = t;
279
- return;
280
- }
281
- }, Z = (t) => {
282
- if (typeof t == "function")
283
- return t;
284
- if (t && typeof t == "object") {
285
- const n = t.default;
286
- if (typeof n == "function")
287
- return n;
288
- if (n && typeof n == "object" && typeof n.default == "function")
289
- return n.default;
290
- }
291
- throw new TypeError("bindings is not a function");
261
+ }, E = (t, n) => {
262
+ if (!Number.isInteger(t) || t < 0)
263
+ throw new RangeError(`${n} width must be a non-negative integer`);
264
+ }, y = (t) => Buffer.isBuffer(t) ? t : t instanceof Uint8Array ? Buffer.from(t.buffer, t.byteOffset, t.byteLength) : Buffer.from(t), X = {
265
+ toBigInt: (t, n = !0) => n ? O(t) : V(t),
266
+ fromBigInt: (t, n, e = !0) => e ? C(t, n) : z(t, n)
292
267
  };
293
- let l = M, d, K = !1;
294
- const Q = () => {
295
- d = void 0;
296
- const t = J();
297
- if (t) return t;
298
- try {
299
- const n = require("bindings"), e = Z(n), r = X();
300
- return e(r ? {
301
- bindings: "bigint_buffer",
302
- module_root: r
303
- } : "bigint_buffer");
304
- } catch (n) {
305
- d = d ?? n;
306
- return;
307
- }
308
- };
309
- if (!_) {
310
- const t = Q();
311
- t !== void 0 ? (l = t, K = !0) : d !== void 0 && process.env?.BIGINT_BUFFER_SILENT_NATIVE_FAIL !== "1" && console.warn(
312
- "bigint-buffer: Failed to load native bindings; using pure JS fallback. Run npm run rebuild to restore native.",
313
- d
314
- );
268
+ let l = X, q = !1;
269
+ if (!b) {
270
+ const t = I();
271
+ t !== void 0 && (l = t, q = !0);
315
272
  }
316
- function Y(t) {
317
- return l.toBigInt(t, !1);
273
+ function Z(t) {
274
+ return l.toBigInt(y(t), !1);
318
275
  }
319
- function lt() {
276
+ function gt() {
320
277
  try {
321
- return Y(Buffer.from([1, 0])) === BigInt(1);
278
+ return Z(Buffer.from([1, 0])) === BigInt(1);
322
279
  } catch {
323
280
  return !1;
324
281
  }
325
282
  }
326
- function tt(t) {
327
- return l.toBigInt(t, !0);
283
+ function J(t) {
284
+ return l.toBigInt(y(t), !0);
328
285
  }
329
- function gt(t, n) {
330
- if (n < 0)
331
- throw new RangeError("toBufferLE width must be non-negative");
286
+ function lt(t, n) {
287
+ E(n, "toBufferLE");
332
288
  const e = n === 0 ? Buffer.alloc(0) : Buffer.allocUnsafe(n);
333
289
  return l.fromBigInt(t, e, !1);
334
290
  }
335
- function nt(t, n) {
336
- if (n < 0)
337
- throw new RangeError("toBufferBE width must be non-negative");
291
+ function K(t, n) {
292
+ E(n, "toBufferBE");
338
293
  const e = n === 0 ? Buffer.alloc(0) : Buffer.allocUnsafe(n);
339
294
  return l.fromBigInt(t, e, !0);
340
295
  }
341
- function et(t) {
296
+ function Q(t) {
342
297
  if (t < BigInt(0))
343
298
  throw new Error("bigintToBuf: negative bigint values are not supported");
344
- const n = C(t);
345
- return nt(t, n);
299
+ const n = M(t);
300
+ return K(t, n);
346
301
  }
347
- function rt(t) {
348
- return tt(t);
302
+ function Y(t) {
303
+ return J(t);
349
304
  }
350
- function Bt(t) {
305
+ function dt(t) {
351
306
  if (t < BigInt(0))
352
307
  throw new Error("bigintToHex: negative bigint values are not supported");
353
308
  const n = t.toString(16);
354
309
  return n.length % 2 === 0 ? n : "0" + n;
355
310
  }
356
- function pt(t) {
311
+ function Bt(t) {
357
312
  const n = t.startsWith("0x") ? t.slice(2) : t;
358
313
  return n.length === 0 ? BigInt(0) : BigInt(`0x${n}`);
359
314
  }
360
315
  function bt(t) {
361
316
  return t.toString(10);
362
317
  }
363
- function ht(t) {
318
+ function pt(t) {
364
319
  if (!t?.trim())
365
320
  throw new Error("textToBigint: input string cannot be empty");
366
321
  try {
@@ -374,59 +329,44 @@ function ht(t) {
374
329
  function mt(t) {
375
330
  if (t < BigInt(0))
376
331
  throw new Error("bigintToBase64: negative bigint values are not supported");
377
- return et(t).toString("base64");
332
+ return Q(t).toString("base64");
378
333
  }
379
- function vt(t) {
334
+ function It(t) {
380
335
  if (!t?.trim())
381
336
  throw new Error("base64ToBigint: input string cannot be empty");
382
337
  const n = t.trim();
383
- if (!/^[A-Za-z0-9+/]+=*$/.test(n))
338
+ if (!/^[A-Za-z0-9+/=_-]+$/.test(n))
384
339
  throw new Error("base64ToBigint: invalid base64 string format");
385
- const e = Buffer.from(n, "base64");
386
- return rt(e);
387
- }
388
- function x() {
389
- if (!f) return;
390
- try {
391
- const n = require.resolve("@gsknnft/bigint-buffer/package.json");
392
- return f.dirname(n);
393
- } catch {
394
- }
395
- if (!a) return;
396
- let t = __dirname;
397
- for (; ; ) {
398
- const n = f.join(t, "package.json");
399
- if (a.existsSync(n))
400
- return t;
401
- const e = f.dirname(t);
402
- if (e === t) break;
403
- t = e;
404
- }
340
+ let e = n.replace(/-/g, "+").replace(/_/g, "/");
341
+ for (; e.length % 4 !== 0; )
342
+ e += "=";
343
+ const r = Buffer.from(e, "base64");
344
+ return Y(r);
405
345
  }
406
346
  export {
407
- L as FIXED_POINT_DECIMALS,
408
- ot as FIXED_POINT_PATTERN,
347
+ k as FIXED_POINT_DECIMALS,
348
+ rt as FIXED_POINT_PATTERN,
409
349
  m as ZERO_FIXED_POINT,
410
- st as addFixedPoint,
411
- ct as averageFixedPoint,
412
- vt as base64ToBigint,
350
+ ft as addFixedPoint,
351
+ ut as averageFixedPoint,
352
+ It as base64ToBigint,
413
353
  mt as bigintToBase64,
414
- et as bigintToBuf,
415
- Bt as bigintToHex,
354
+ Q as bigintToBuf,
355
+ dt as bigintToHex,
416
356
  bt as bigintToText,
417
- rt as bufToBigint,
418
- at as compareFixedPoint,
419
- dt as fixedPointToBigInt,
420
- ft as fromFixedPoint,
421
- pt as hexToBigint,
422
- K as isNative,
423
- ut as subtractFixedPoint,
424
- ht as textToBigint,
425
- tt as toBigIntBE,
426
- Y as toBigIntLE,
427
- c as toBigIntValue,
428
- nt as toBufferBE,
429
- gt as toBufferLE,
430
- it as toFixedPoint,
431
- lt as validateBigIntBuffer
357
+ Y as bufToBigint,
358
+ ct as compareFixedPoint,
359
+ at as fixedPointToBigInt,
360
+ it as fromFixedPoint,
361
+ Bt as hexToBigint,
362
+ q as isNative,
363
+ st as subtractFixedPoint,
364
+ pt as textToBigint,
365
+ J as toBigIntBE,
366
+ Z as toBigIntLE,
367
+ u as toBigIntValue,
368
+ K as toBufferBE,
369
+ lt as toBufferLE,
370
+ ot as toFixedPoint,
371
+ gt as validateBigIntBuffer
432
372
  };
package/dist/index.umd.js CHANGED
@@ -1 +1 @@
1
- (function(o,d){typeof exports=="object"&&typeof module<"u"?d(exports):typeof define=="function"&&define.amd?define(["exports"],d):(o=typeof globalThis<"u"?globalThis:o||self,d(o["bigint-buffer"]={}))})(this,(function(o){"use strict";let d=!1,b,h;const p=typeof globalThis<"u"&&typeof globalThis.document<"u";let u,v;typeof process<"u"&&process.versions?.node&&!p&&(u=require("path"),v=require("fs"));const E=()=>{if(u)try{const t=require.resolve("@gsknnft/bigint-buffer/package.json");return u.dirname(t)}catch{return}},S=()=>{if(!u)return[];const t=new Set,n=r=>{if(!r)return;const f=u.resolve(r);t.has(f)||t.add(f)},e=E(),i=typeof process<"u"&&process.resourcesPath;return n(process.env?.BIGINT_BUFFER_NATIVE_PATH),n(e),n(e?u.join(e,"dist"):void 0),n(i?u.join(i,"app.asar.unpacked","node_modules","@gsknnft","bigint-buffer"):void 0),n(u.resolve(__dirname,"..")),n(u.resolve(__dirname,"../..")),n(u.resolve(__dirname,"../../..")),n(u.resolve(__dirname,"../../../..")),n(u.resolve(__dirname,"../../../../..")),Array.from(t)},k=()=>{if(!(!u||!v))for(const t of S()){const n=u.join(t,"build","Release","bigint_buffer.node");if(v.existsSync(n))return t}},$=t=>{if(typeof t=="function")return t;if(t&&typeof t=="object"){const n=t.default;if(typeof n=="function")return n;if(n&&typeof n=="object"&&typeof n.default=="function")return n.default}throw new TypeError("bindings is not a function")},j=()=>{if(u)try{const t=require("node-gyp-build"),n=E();return n?t(n):void 0}catch(t){h=t;return}};function T(){const t=j();if(t)return t;try{const n=require("bindings"),e=$(n),i=k();return e(i?{bindings:"bigint_buffer",module_root:i}:"bigint_buffer")}catch(n){h=n;return}}p||(b=T(),d=b!==void 0,!d&&h!==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.",h)),b===void 0&&(b={toBigInt:(t,n=!0)=>{const e=Buffer.from(t);n||e.reverse();const i=e.toString("hex");return i.length===0?0n:BigInt(`0x${i}`)},fromBigInt:(t,n,e=!0)=>{const i=t.toString(16),r=n.length,f=i.padStart(r*2,"0").slice(0,r*2),a=Buffer.from(f,"hex");return e||a.reverse(),a.copy(n),n}}),p||T();function y(t,n=!1,e){const i=t.match(/^(0x)?([\da-fA-F]+)$/);if(i==null)throw new RangeError("input must be a hexadecimal string, e.g. '0x124fe3a' or '0214f1b2'");let r=i[2];return n?"0x"+r:r}function A(t,n=!1,e){if(t<0)throw RangeError("a should be a non-negative integer. Negative values are not supported");return y(t.toString(16),n)}function U(t){return BigInt(y(t,!0))}const _=9,O=/^-?0x[0-9a-f]+$/i,m="0x0",W=t=>t.startsWith("0x")||t.startsWith("0X")?t:`0x${t}`,I=t=>{if(t===0n)return m;const n=t<0n,e=n?-t:t,i=A(e);return`${n?"-":""}0x${i}`},c=t=>{if(!t)return 0n;const n=t.trim();if(n.length===0)return 0n;const e=n.startsWith("-"),i=e?n.slice(1):n,r=W(i),f=U(r);return e?-f:f};function q(t,n=_){if(!Number.isFinite(t))return m;const e=10n**BigInt(n),i=BigInt(Math.round(t*Number(e)));return I(i)}function D(t,n=9){if(!t)return 0;const e=t.trim();if(e.length===0)return 0;const i=e.startsWith("-"),r=i?e.slice(1):e,f=i?-BigInt(r):BigInt(r),a=10**n;return Number(f)/a}function H(t,n){return I(c(t)+c(n))}function V(t,n){return I(c(t)-c(n))}function G(t){if(t.length===0)return m;const n=t.reduce((e,i)=>e+c(i),0n);return I(n/BigInt(t.length))}function M(t,n){const e=c(t)-c(n);return e===0n?0:e>0n?1:-1}function X(t){return c(t)}const C=typeof Buffer.prototype.readBigUInt64LE=="function",z=typeof Buffer.prototype.readBigUInt64BE=="function",Z=typeof Buffer.prototype.writeBigUInt64LE=="function",J=typeof Buffer.prototype.writeBigUInt64BE=="function",K=C?(t,n)=>t.readBigUInt64LE(n):(t,n)=>{let e=0n;for(let i=7;i>=0;i--)e=(e<<8n)+BigInt(t[n+i]);return e},Q=z?(t,n)=>t.readBigUInt64BE(n):(t,n)=>{let e=0n;for(let i=0;i<8;i++)e=(e<<8n)+BigInt(t[n+i]);return e},Y=Z?(t,n,e)=>{t.writeBigUInt64LE(e,n)}:(t,n,e)=>{let i=e;for(let r=0;r<8;r++)t[n+r]=Number(i&0xffn),i>>=8n},tt=J?(t,n,e)=>{t.writeBigUInt64BE(e,n)}:(t,n,e)=>{let i=e;for(let r=7;r>=0;r--)t[n+r]=Number(i&0xffn),i>>=8n},nt=t=>{let n=0n,e=1n;const i=t.length,r=i&7;for(let f=0;f<r;f++)n+=BigInt(t[f])*e,e<<=8n;for(let f=r;f<i;f+=8){const a=K(t,f);n+=a*e,e<<=64n}return n},et=t=>{const n=t.length;if(n===0)return 0n;let e=0n;const i=n&7;let r=0;if(i!==0)for(;r<i;r++)e=(e<<8n)+BigInt(t[r]);for(;r<n;r+=8){const f=Q(t,r);e=(e<<64n)+f}return e},it=(t,n)=>{const e=n.length;let i=t,r=0;const f=e-e%8;for(;r<f;r+=8)Y(n,r,i&0xffffffffffffffffn),i>>=64n;for(;r<e;r++)n[r]=Number(i&0xffn),i>>=8n;return n},rt=(t,n)=>{const e=n.length;let i=t,r=e;const f=e&-8;for(;r>f;)r--,n[r]=Number(i&0xffn),i>>=8n;for(;r>0;r-=8){const a=i&0xffffffffffffffffn;tt(n,r-8,a),i>>=64n}return n},ot=t=>{if(t===0n)return 1;let n=t,e=0;for(;n>0n;)e++,n>>=8n;return e},ft={toBigInt:(t,n=!0)=>n?et(t):nt(t),fromBigInt:(t,n,e=!0)=>e?rt(t,n):it(t,n)},w=typeof globalThis<"u"&&typeof globalThis.document<"u";let s,g;w||(s=require("path"),g=require("fs"));const st=()=>{if(!s)return[];const t=L(),n=typeof process<"u"&&process.resourcesPath;return[process.env?.BIGINT_BUFFER_NATIVE_PATH,t,t?s.join(t,"dist"):void 0,n?s.join(n,"app.asar.unpacked","node_modules","@gsknnft","bigint-buffer"):void 0,s.resolve(__dirname,".."),s.resolve(__dirname,"."),s.resolve(__dirname,"../.."),s.resolve(__dirname,"../../.."),s.resolve(__dirname,"../../../..")].filter(e=>!!e)},ut=()=>{if(!(!s||!g))for(const t of st()){const n=s.join(t,"build","Release","bigint_buffer.node");if(g.existsSync(n))return t;const e=s.join(t,"dist","build","Release","bigint_buffer.node");if(g.existsSync(e))return s.join(t,"dist")}},ct=()=>{if(s)try{const t=require("node-gyp-build"),n=L();return n?t(n):void 0}catch(t){l=t;return}},at=t=>{if(typeof t=="function")return t;if(t&&typeof t=="object"){const n=t.default;if(typeof n=="function")return n;if(n&&typeof n=="object"&&typeof n.default=="function")return n.default}throw new TypeError("bindings is not a function")};let B=ft,l;o.isNative=!1;const dt=()=>{l=void 0;const t=ct();if(t)return t;try{const n=require("bindings"),e=at(n),i=ut();return e(i?{bindings:"bigint_buffer",module_root:i}:"bigint_buffer")}catch(n){l=l??n;return}};if(!w){const t=dt();t!==void 0?(B=t,o.isNative=!0):l!==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.",l)}function N(t){return B.toBigInt(t,!1)}function gt(){try{return N(Buffer.from([1,0]))===BigInt(1)}catch{return!1}}function R(t){return B.toBigInt(t,!0)}function lt(t,n){if(n<0)throw new RangeError("toBufferLE width must be non-negative");const e=n===0?Buffer.alloc(0):Buffer.allocUnsafe(n);return B.fromBigInt(t,e,!1)}function x(t,n){if(n<0)throw new RangeError("toBufferBE width must be non-negative");const e=n===0?Buffer.alloc(0):Buffer.allocUnsafe(n);return B.fromBigInt(t,e,!0)}function P(t){if(t<BigInt(0))throw new Error("bigintToBuf: negative bigint values are not supported");const n=ot(t);return x(t,n)}function F(t){return R(t)}function Bt(t){if(t<BigInt(0))throw new Error("bigintToHex: negative bigint values are not supported");const n=t.toString(16);return n.length%2===0?n:"0"+n}function bt(t){const n=t.startsWith("0x")?t.slice(2):t;return n.length===0?BigInt(0):BigInt(`0x${n}`)}function ht(t){return t.toString(10)}function mt(t){if(!t?.trim())throw new Error("textToBigint: input string cannot be empty");try{return BigInt(t)}catch(n){throw new Error(`textToBigint: invalid decimal string "${t}" ${n instanceof Error?n.message:String(n)}`)}}function It(t){if(t<BigInt(0))throw new Error("bigintToBase64: negative bigint values are not supported");return P(t).toString("base64")}function pt(t){if(!t?.trim())throw new Error("base64ToBigint: input string cannot be empty");const n=t.trim();if(!/^[A-Za-z0-9+/]+=*$/.test(n))throw new Error("base64ToBigint: invalid base64 string format");const e=Buffer.from(n,"base64");return F(e)}function L(){if(!s)return;try{const n=require.resolve("@gsknnft/bigint-buffer/package.json");return s.dirname(n)}catch{}if(!g)return;let t=__dirname;for(;;){const n=s.join(t,"package.json");if(g.existsSync(n))return t;const e=s.dirname(t);if(e===t)break;t=e}}o.FIXED_POINT_DECIMALS=_,o.FIXED_POINT_PATTERN=O,o.ZERO_FIXED_POINT=m,o.addFixedPoint=H,o.averageFixedPoint=G,o.base64ToBigint=pt,o.bigintToBase64=It,o.bigintToBuf=P,o.bigintToHex=Bt,o.bigintToText=ht,o.bufToBigint=F,o.compareFixedPoint=M,o.fixedPointToBigInt=X,o.fromFixedPoint=D,o.hexToBigint=bt,o.subtractFixedPoint=V,o.textToBigint=mt,o.toBigIntBE=R,o.toBigIntLE=N,o.toBigIntValue=c,o.toBufferBE=x,o.toBufferLE=lt,o.toFixedPoint=q,o.validateBigIntBuffer=gt,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(o,a){typeof exports=="object"&&typeof module<"u"?a(exports):typeof define=="function"&&define.amd?define(["exports"],a):(o=typeof globalThis<"u"?globalThis:o||self,a(o["bigint-buffer"]={}))})(this,(function(o){"use strict";let a;const b=typeof globalThis<"u"&&typeof globalThis.document<"u";let s,g;typeof process<"u"&&process.versions?.node&&!b&&(s=require("path"),g=require("fs"));const I=()=>{if(!s||!g)return;let t=__dirname;for(;;){const f=s.join(t,"node_modules","@gsknnft","bigint-buffer","package.json");if(g.existsSync(f))return s.dirname(f);const u=s.dirname(t);if(u===t)break;t=u}const n=typeof require=="function"&&typeof require.resolve=="function",e=f=>{if(n)try{return require.resolve(f)}catch{return}},i=e("@gsknnft/bigint-buffer")??e("@gsknnft/bigint-buffer/dist/index.cjs")??e("@gsknnft/bigint-buffer/dist/index.js");let r=i?s.dirname(i):__dirname;for(;;){const f=s.join(r,"package.json");if(g.existsSync(f))return r;const u=s.dirname(r);if(u===r)break;r=u}},N=()=>{if(!s)return[];const t=new Set,n=f=>{if(!f)return;const u=s.resolve(f);t.has(u)||t.add(u)},e=I(),i=typeof process<"u"&&process.resourcesPath;n(process.env?.BIGINT_BUFFER_NATIVE_PATH),n(e),n(e?s.join(e,"dist"):void 0),n(i?s.join(i,"app.asar.unpacked","node_modules","@gsknnft","bigint-buffer"):void 0),n(s.resolve(__dirname,"..")),n(s.resolve(__dirname,"../..")),n(s.resolve(__dirname,"../../..")),n(s.resolve(__dirname,"../../../..")),n(s.resolve(__dirname,"../../../../.."));const r=Array.from(t);return process.env.BIGINT_BUFFER_DEBUG&&console.log("bigint-buffer: candidateRoots:",r),r},R=()=>{if(!(!s||!g)){for(const t of N()){const n=s.join(t,"build","Release","bigint_buffer.node");if(process.env.BIGINT_BUFFER_DEBUG&&console.log("bigint-buffer: checking for native at",n),g.existsSync(n))return process.env.BIGINT_BUFFER_DEBUG&&console.log("bigint-buffer: found native at",n),t;const e=s.join(t,"dist","build","Release","bigint_buffer.node");if(process.env.BIGINT_BUFFER_DEBUG&&console.log("bigint-buffer: checking for native at",e),g.existsSync(e))return process.env.BIGINT_BUFFER_DEBUG&&console.log("bigint-buffer: found native at",e),s.join(t,"dist")}process.env.BIGINT_BUFFER_DEBUG&&console.warn("bigint-buffer: native binary not found in any candidate root")}},x=t=>{if(typeof t=="function")return t;if(t&&typeof t=="object"){const n=t.default;if(typeof n=="function")return n;if(n&&typeof n=="object"&&typeof n.default=="function")return n.default}throw new TypeError("bindings is not a function")},U=()=>{if(s)try{const t=require("node-gyp-build"),n=I();return n?t(n):void 0}catch(t){a=t;return}};function E(){a=void 0;const t=U();if(t)return t;try{const n=require("bindings"),e=x(n),i=I(),r=R()??i;return e(r?{bindings:"bigint_buffer",module_root:r}:"bigint_buffer")}catch(n){a=n,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.",a)}}Buffer.prototype.readBigUInt64LE,Buffer.prototype.readBigUInt64BE,Buffer.prototype.writeBigUInt64LE,Buffer.prototype.writeBigUInt64BE,b||E();function h(t,n=!1,e){const i=t.match(/^(0x)?([\da-fA-F]+)$/);if(i==null)throw new RangeError("input must be a hexadecimal string, e.g. '0x124fe3a' or '0214f1b2'");let r=i[2];return n?"0x"+r:r}function P(t,n=!1,e){if(t<0)throw RangeError("a should be a non-negative integer. Negative values are not supported");return h(t.toString(16),n)}function L(t){return BigInt(h(t,!0))}const m=9,k=/^-?0x[0-9a-f]+$/i,l="0x0",S=t=>t.startsWith("0x")||t.startsWith("0X")?t:`0x${t}`,B=t=>{if(t===0n)return l;const n=t<0n,e=n?-t:t,i=P(e);return`${n?"-":""}0x${i}`},c=t=>{if(!t)return 0n;const n=t.trim();if(n.length===0)return 0n;const e=n.startsWith("-"),i=e?n.slice(1):n,r=S(i),f=L(r);return e?-f:f};function j(t,n=m){if(!Number.isFinite(t))return l;const e=10n**BigInt(n),i=BigInt(Math.round(t*Number(e)));return B(i)}function D(t,n=9){if(!t)return 0;const e=t.trim();if(e.length===0)return 0;const i=e.startsWith("-"),r=i?e.slice(1):e,f=i?-BigInt(r):BigInt(r),u=10**n;return Number(f)/u}function G(t,n){return B(c(t)+c(n))}function A(t,n){return B(c(t)-c(n))}function $(t){if(t.length===0)return l;const n=t.reduce((e,i)=>e+c(i),0n);return B(n/BigInt(t.length))}function O(t,n){const e=c(t)-c(n);return e===0n?0:e>0n?1:-1}function W(t){return c(t)}const H=typeof Buffer.prototype.readBigUInt64LE=="function",V=typeof Buffer.prototype.readBigUInt64BE=="function",q=typeof Buffer.prototype.writeBigUInt64LE=="function",C=typeof Buffer.prototype.writeBigUInt64BE=="function",X=H?(t,n)=>t.readBigUInt64LE(n):(t,n)=>{let e=0n;for(let i=7;i>=0;i--)e=(e<<8n)+BigInt(t[n+i]);return e},M=V?(t,n)=>t.readBigUInt64BE(n):(t,n)=>{let e=0n;for(let i=0;i<8;i++)e=(e<<8n)+BigInt(t[n+i]);return e},z=q?(t,n,e)=>{t.writeBigUInt64LE(e,n)}:(t,n,e)=>{let i=e;for(let r=0;r<8;r++)t[n+r]=Number(i&0xffn),i>>=8n},Z=C?(t,n,e)=>{t.writeBigUInt64BE(e,n)}:(t,n,e)=>{let i=e;for(let r=7;r>=0;r--)t[n+r]=Number(i&0xffn),i>>=8n},J=t=>{let n=0n,e=1n;const i=t.length,r=i&7;for(let f=0;f<r;f++)n+=BigInt(t[f])*e,e<<=8n;for(let f=r;f<i;f+=8){const u=X(t,f);n+=u*e,e<<=64n}return n},K=t=>{const n=t.length;if(n===0)return 0n;let e=0n;const i=n&7;let r=0;if(i!==0)for(;r<i;r++)e=(e<<8n)+BigInt(t[r]);for(;r<n;r+=8){const f=M(t,r);e=(e<<64n)+f}return e},Q=(t,n)=>{const e=n.length;let i=t,r=0;const f=e-e%8;for(;r<f;r+=8)z(n,r,i&0xffffffffffffffffn),i>>=64n;for(;r<e;r++)n[r]=Number(i&0xffn),i>>=8n;return n},Y=(t,n)=>{const e=n.length;let i=t,r=e;const f=e&-8;for(;r>f;)r--,n[r]=Number(i&0xffn),i>>=8n;for(;r>0;r-=8){const u=i&0xffffffffffffffffn;Z(n,r-8,u),i>>=64n}return n},tt=t=>{if(t===0n)return 1;let n=t,e=0;for(;n>0n;)e++,n>>=8n;return e},p=(t,n)=>{if(!Number.isInteger(t)||t<0)throw new RangeError(`${n} width must be a non-negative integer`)},y=t=>Buffer.isBuffer(t)?t:t instanceof Uint8Array?Buffer.from(t.buffer,t.byteOffset,t.byteLength):Buffer.from(t);let d={toBigInt:(t,n=!0)=>n?K(t):J(t),fromBigInt:(t,n,e=!0)=>e?Y(t,n):Q(t,n)};if(o.isNative=!1,!b){const t=E();t!==void 0&&(d=t,o.isNative=!0)}function T(t){return d.toBigInt(y(t),!1)}function nt(){try{return T(Buffer.from([1,0]))===BigInt(1)}catch{return!1}}function v(t){return d.toBigInt(y(t),!0)}function et(t,n){p(n,"toBufferLE");const e=n===0?Buffer.alloc(0):Buffer.allocUnsafe(n);return d.fromBigInt(t,e,!1)}function _(t,n){p(n,"toBufferBE");const e=n===0?Buffer.alloc(0):Buffer.allocUnsafe(n);return d.fromBigInt(t,e,!0)}function w(t){if(t<BigInt(0))throw new Error("bigintToBuf: negative bigint values are not supported");const n=tt(t);return _(t,n)}function F(t){return v(t)}function it(t){if(t<BigInt(0))throw new Error("bigintToHex: negative bigint values are not supported");const n=t.toString(16);return n.length%2===0?n:"0"+n}function rt(t){const n=t.startsWith("0x")?t.slice(2):t;return n.length===0?BigInt(0):BigInt(`0x${n}`)}function ot(t){return t.toString(10)}function ft(t){if(!t?.trim())throw new Error("textToBigint: input string cannot be empty");try{return BigInt(t)}catch(n){throw new Error(`textToBigint: invalid decimal string "${t}" ${n instanceof Error?n.message:String(n)}`)}}function st(t){if(t<BigInt(0))throw new Error("bigintToBase64: negative bigint values are not supported");return w(t).toString("base64")}function ut(t){if(!t?.trim())throw new Error("base64ToBigint: input string cannot be empty");const n=t.trim();if(!/^[A-Za-z0-9+/=_-]+$/.test(n))throw new Error("base64ToBigint: invalid base64 string format");let e=n.replace(/-/g,"+").replace(/_/g,"/");for(;e.length%4!==0;)e+="=";const i=Buffer.from(e,"base64");return F(i)}o.FIXED_POINT_DECIMALS=m,o.FIXED_POINT_PATTERN=k,o.ZERO_FIXED_POINT=l,o.addFixedPoint=G,o.averageFixedPoint=$,o.base64ToBigint=ut,o.bigintToBase64=st,o.bigintToBuf=w,o.bigintToHex=it,o.bigintToText=ot,o.bufToBigint=F,o.compareFixedPoint=O,o.fixedPointToBigInt=W,o.fromFixedPoint=D,o.hexToBigint=rt,o.subtractFixedPoint=A,o.textToBigint=ft,o.toBigIntBE=v,o.toBigIntLE=T,o.toBigIntValue=c,o.toBufferBE=_,o.toBufferLE=et,o.toFixedPoint=j,o.validateBigIntBuffer=nt,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})}));