@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.
- package/README.md +150 -144
- package/dist/build/Release/bigint_buffer.node +0 -0
- package/dist/conversion/bundle.iife.js +421 -0
- package/dist/conversion/bundle.umd.js +423 -0
- package/dist/conversion/cjs/converter.d.ts +14 -0
- package/dist/conversion/cjs/index.d.ts +33 -0
- package/dist/conversion/cjs/index.js +418 -0
- package/dist/conversion/cjs/index.node.js +4 -0
- package/dist/conversion/cjs/package.json +1 -0
- package/dist/conversion/converter.d.ts +14 -0
- package/dist/conversion/esm/bundle.js +416 -0
- package/dist/conversion/esm/bundle.min.js +1 -0
- package/dist/conversion/esm/converter.d.ts +14 -0
- package/dist/conversion/esm/index.browser.js +416 -0
- package/dist/conversion/esm/index.d.ts +33 -0
- package/dist/conversion/esm/index.js +416 -0
- package/dist/conversion/esm/index.node.js +2 -0
- package/dist/conversion/esm/package.json +1 -0
- package/dist/conversion/index.d.ts +1 -2
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.js +190 -250
- package/dist/index.umd.js +1 -1
- package/dist/types/conversion/index.d.ts +1 -2
- package/dist/types/conversion/src/index.d.ts +2 -0
- package/dist/types/conversion/src/ts/index.d.ts +4 -2
- package/dist/types/index.d.ts +4 -3
- package/package.json +141 -136
- package/scripts/postinstall.cjs +5 -3
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/dist/types/bigint-buffer.test.d.ts +0 -1
- package/dist/types/conversion/test/bigintToBase64.test.d.ts +0 -1
- package/dist/types/conversion/test/bigintToBuf.test.d.ts +0 -1
- package/dist/types/conversion/test/bigintToHex.test.d.ts +0 -1
- package/dist/types/conversion/test/bigintToText.test.d.ts +0 -1
- package/dist/types/conversion/test/bufToBigint.test.d.ts +0 -1
- package/dist/types/conversion/test/fixedPoint.test.d.ts +0 -1
- package/dist/types/conversion/test/hexToBigint.test.d.ts +0 -1
- package/dist/types/conversion/test/hexToBuf.test.d.ts +0 -1
- package/dist/types/conversion/test/parseHex.test.d.ts +0 -1
- package/dist/types/conversion/test/setup.test.d.ts +0 -1
- package/dist/types/conversion/test/textToBuf.test.d.ts +0 -1
- package/dist/types/conversion/vite.config.d.ts +0 -2
- package/dist/types/conversion/vitest.config.d.ts +0 -2
- package/dist/types/index.bench.d.ts +0 -1
- package/dist/types/index.spec.d.ts +0 -1
package/dist/index.js
CHANGED
|
@@ -1,39 +1,84 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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(
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
-
|
|
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
|
-
},
|
|
48
|
-
if (
|
|
92
|
+
}, N = () => {
|
|
93
|
+
if (f)
|
|
49
94
|
try {
|
|
50
|
-
const t =
|
|
95
|
+
const t = a("node-gyp-build"), n = p();
|
|
51
96
|
return n ? t(n) : void 0;
|
|
52
97
|
} catch (t) {
|
|
53
|
-
|
|
98
|
+
d = t;
|
|
54
99
|
return;
|
|
55
100
|
}
|
|
56
101
|
};
|
|
57
|
-
function
|
|
58
|
-
|
|
102
|
+
function I() {
|
|
103
|
+
d = void 0;
|
|
104
|
+
const t = N();
|
|
59
105
|
if (t) return t;
|
|
60
106
|
try {
|
|
61
|
-
const n =
|
|
62
|
-
return e(
|
|
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:
|
|
110
|
+
module_root: o
|
|
65
111
|
} : "bigint_buffer");
|
|
66
112
|
} catch (n) {
|
|
67
|
-
|
|
68
|
-
|
|
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
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
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
|
|
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
|
|
138
|
+
return h(t.toString(16), n);
|
|
103
139
|
}
|
|
104
|
-
function
|
|
105
|
-
return BigInt(
|
|
140
|
+
function L(t) {
|
|
141
|
+
return BigInt(h(t, !0));
|
|
106
142
|
}
|
|
107
|
-
const
|
|
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 =
|
|
146
|
+
const n = t < 0n, e = n ? -t : t, r = U(e);
|
|
111
147
|
return `${n ? "-" : ""}0x${r}`;
|
|
112
|
-
},
|
|
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 =
|
|
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
|
|
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
|
|
161
|
+
return B(r);
|
|
126
162
|
}
|
|
127
|
-
function
|
|
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),
|
|
132
|
-
return Number(i) /
|
|
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
|
|
135
|
-
return
|
|
170
|
+
function ft(t, n) {
|
|
171
|
+
return B(u(t) + u(n));
|
|
136
172
|
}
|
|
137
|
-
function
|
|
138
|
-
return
|
|
173
|
+
function st(t, n) {
|
|
174
|
+
return B(u(t) - u(n));
|
|
139
175
|
}
|
|
140
|
-
function
|
|
176
|
+
function ut(t) {
|
|
141
177
|
if (t.length === 0)
|
|
142
178
|
return m;
|
|
143
|
-
const n = t.reduce((e, r) => e +
|
|
144
|
-
return
|
|
179
|
+
const n = t.reduce((e, r) => e + u(r), 0n);
|
|
180
|
+
return B(n / BigInt(t.length));
|
|
145
181
|
}
|
|
146
|
-
function
|
|
147
|
-
const e =
|
|
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
|
|
151
|
-
return
|
|
186
|
+
function at(t) {
|
|
187
|
+
return u(t);
|
|
152
188
|
}
|
|
153
|
-
const
|
|
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
|
-
},
|
|
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
|
-
},
|
|
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 =
|
|
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
|
|
182
|
-
n +=
|
|
217
|
+
const s = $(t, i);
|
|
218
|
+
n += s * e, e <<= 64n;
|
|
183
219
|
}
|
|
184
220
|
return n;
|
|
185
|
-
},
|
|
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 =
|
|
231
|
+
const i = A(t, o);
|
|
196
232
|
e = (e << 64n) + i;
|
|
197
233
|
}
|
|
198
234
|
return e;
|
|
199
|
-
},
|
|
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
|
-
|
|
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
|
-
},
|
|
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
|
|
216
|
-
H(n, o - 8,
|
|
251
|
+
const s = r & 0xffffffffffffffffn;
|
|
252
|
+
H(n, o - 8, s), r >>= 64n;
|
|
217
253
|
}
|
|
218
254
|
return n;
|
|
219
|
-
},
|
|
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
|
-
},
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
},
|
|
229
|
-
|
|
230
|
-
|
|
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 =
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
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
|
|
317
|
-
return l.toBigInt(t, !1);
|
|
273
|
+
function Z(t) {
|
|
274
|
+
return l.toBigInt(y(t), !1);
|
|
318
275
|
}
|
|
319
|
-
function
|
|
276
|
+
function gt() {
|
|
320
277
|
try {
|
|
321
|
-
return
|
|
278
|
+
return Z(Buffer.from([1, 0])) === BigInt(1);
|
|
322
279
|
} catch {
|
|
323
280
|
return !1;
|
|
324
281
|
}
|
|
325
282
|
}
|
|
326
|
-
function
|
|
327
|
-
return l.toBigInt(t, !0);
|
|
283
|
+
function J(t) {
|
|
284
|
+
return l.toBigInt(y(t), !0);
|
|
328
285
|
}
|
|
329
|
-
function
|
|
330
|
-
|
|
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
|
|
336
|
-
|
|
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
|
|
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 =
|
|
345
|
-
return
|
|
299
|
+
const n = M(t);
|
|
300
|
+
return K(t, n);
|
|
346
301
|
}
|
|
347
|
-
function
|
|
348
|
-
return
|
|
302
|
+
function Y(t) {
|
|
303
|
+
return J(t);
|
|
349
304
|
}
|
|
350
|
-
function
|
|
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
|
|
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
|
|
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
|
|
332
|
+
return Q(t).toString("base64");
|
|
378
333
|
}
|
|
379
|
-
function
|
|
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
|
|
338
|
+
if (!/^[A-Za-z0-9+/=_-]+$/.test(n))
|
|
384
339
|
throw new Error("base64ToBigint: invalid base64 string format");
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
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
|
-
|
|
408
|
-
|
|
347
|
+
k as FIXED_POINT_DECIMALS,
|
|
348
|
+
rt as FIXED_POINT_PATTERN,
|
|
409
349
|
m as ZERO_FIXED_POINT,
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
350
|
+
ft as addFixedPoint,
|
|
351
|
+
ut as averageFixedPoint,
|
|
352
|
+
It as base64ToBigint,
|
|
413
353
|
mt as bigintToBase64,
|
|
414
|
-
|
|
415
|
-
|
|
354
|
+
Q as bigintToBuf,
|
|
355
|
+
dt as bigintToHex,
|
|
416
356
|
bt as bigintToText,
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
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,
|
|
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"})}));
|