@gsknnft/bigint-buffer 1.4.3 → 1.4.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +98 -89
- package/build/Release/bigint_buffer.iobj +0 -0
- package/build/Release/bigint_buffer.ipdb +0 -0
- package/build/Release/bigint_buffer.node +0 -0
- package/build/Release/bigint_buffer.pdb +0 -0
- package/build/Release/obj/bigint_buffer/src/bigint-buffer.obj +0 -0
- package/build/Release/obj/bigint_buffer/win_delay_load_hook.obj +0 -0
- package/build/binding.sln +3 -3
- package/build/conversion/index.js +18 -0
- package/build/conversion/index.js.map +1 -0
- package/build/conversion/src/ts/fixedPoint/index.d.ts +12 -0
- package/build/conversion/src/ts/fixedPoint/index.js +79 -0
- package/build/conversion/src/ts/fixedPoint/index.js.map +1 -0
- package/build/conversion/src/ts/index.d.ts +169 -0
- package/build/conversion/src/ts/index.js +453 -0
- package/build/conversion/src/ts/index.js.map +1 -0
- package/build/conversion/test/bigintToBase64.test.js +72 -0
- package/build/conversion/test/bigintToBase64.test.js.map +1 -0
- package/build/conversion/test/bigintToBuf.test.js +77 -0
- package/build/conversion/test/bigintToBuf.test.js.map +1 -0
- package/build/conversion/test/bigintToHex.test.js +86 -0
- package/build/conversion/test/bigintToHex.test.js.map +1 -0
- package/build/conversion/test/bigintToText.test.js +63 -0
- package/build/conversion/test/bigintToText.test.js.map +1 -0
- package/build/conversion/test/bufToBigint.test.js +55 -0
- package/build/conversion/test/bufToBigint.test.js.map +1 -0
- package/build/conversion/test/hexToBigint.test.js +56 -0
- package/build/conversion/test/hexToBigint.test.js.map +1 -0
- package/build/conversion/test/hexToBuf.test.js +73 -0
- package/build/conversion/test/hexToBuf.test.js.map +1 -0
- package/build/conversion/test/parseHex.test.js +69 -0
- package/build/conversion/test/parseHex.test.js.map +1 -0
- package/build/conversion/test/textToBuf.test.js +59 -0
- package/build/conversion/test/textToBuf.test.js.map +1 -0
- package/build/index.js +242 -0
- package/build/index.js.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +257 -200
- package/dist/index.umd.js +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/conversion/src/ts/fixedPoint/index.d.ts +12 -0
- package/dist/types/conversion/src/ts/index.d.ts +1 -0
- package/package.json +132 -132
- package/src/conversion/docs/README.md +9 -1
- package/src/conversion/src/docs/index.md +6 -1
- package/src/conversion/src/ts/fixedPoint/index.ts +87 -0
- package/src/conversion/src/ts/index.ts +15 -0
- /package/dist/types/dist/dist/{types/index.d.ts → index.d.ts} +0 -0
package/build/index.js
ADDED
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.isNative = exports.conversionUtils = void 0;
|
|
37
|
+
exports.toBigIntLE = toBigIntLE;
|
|
38
|
+
exports.validateBigIntBuffer = validateBigIntBuffer;
|
|
39
|
+
exports.toBigIntBE = toBigIntBE;
|
|
40
|
+
exports.toBufferLE = toBufferLE;
|
|
41
|
+
exports.toBufferBE = toBufferBE;
|
|
42
|
+
exports.bigintToBuf = bigintToBuf;
|
|
43
|
+
exports.bufToBigint = bufToBigint;
|
|
44
|
+
exports.bigintToHex = bigintToHex;
|
|
45
|
+
exports.hexToBigint = hexToBigint;
|
|
46
|
+
exports.bigintToText = bigintToText;
|
|
47
|
+
exports.textToBigint = textToBigint;
|
|
48
|
+
exports.bigintToBase64 = bigintToBase64;
|
|
49
|
+
exports.base64ToBigint = base64ToBigint;
|
|
50
|
+
// Export robust Buffer/BigInt methods at top level
|
|
51
|
+
const conversionUtils = __importStar(require("./conversion/src/ts/index"));
|
|
52
|
+
exports.conversionUtils = conversionUtils;
|
|
53
|
+
let converter;
|
|
54
|
+
exports.isNative = false;
|
|
55
|
+
if (typeof window === "undefined") {
|
|
56
|
+
try {
|
|
57
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
58
|
+
converter = require("bindings")("bigint_buffer");
|
|
59
|
+
exports.isNative = converter !== undefined;
|
|
60
|
+
}
|
|
61
|
+
catch (e) {
|
|
62
|
+
console.warn("bigint: Failed to load bindings, pure JS will be used (try npm run rebuild?)", e);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Convert a little-endian buffer into a BigInt.
|
|
67
|
+
* @param buf The little-endian buffer to convert
|
|
68
|
+
* @returns A BigInt with the little-endian representation of buf.
|
|
69
|
+
*/
|
|
70
|
+
function toBigIntLE(buf) {
|
|
71
|
+
if (typeof window !== "undefined" || converter === undefined) {
|
|
72
|
+
const reversed = Buffer.from(buf);
|
|
73
|
+
reversed.reverse();
|
|
74
|
+
const hex = reversed.toString("hex");
|
|
75
|
+
if (hex.length === 0) {
|
|
76
|
+
return BigInt(0);
|
|
77
|
+
}
|
|
78
|
+
return BigInt(`0x${hex}`);
|
|
79
|
+
}
|
|
80
|
+
return converter.toBigInt(buf, false);
|
|
81
|
+
}
|
|
82
|
+
function validateBigIntBuffer() {
|
|
83
|
+
try {
|
|
84
|
+
const test = toBigIntLE(Buffer.from([0x01, 0x00]));
|
|
85
|
+
return test === BigInt(1);
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Convert a big-endian buffer into a BigInt
|
|
93
|
+
* @param buf The big-endian buffer to convert.
|
|
94
|
+
* @returns A BigInt with the big-endian representation of buf.
|
|
95
|
+
*/
|
|
96
|
+
function toBigIntBE(buf) {
|
|
97
|
+
if (typeof window !== "undefined" || converter === undefined) {
|
|
98
|
+
const hex = buf.toString("hex");
|
|
99
|
+
if (hex.length === 0) {
|
|
100
|
+
return BigInt(0);
|
|
101
|
+
}
|
|
102
|
+
return BigInt(`0x${hex}`);
|
|
103
|
+
}
|
|
104
|
+
return converter.toBigInt(buf, true);
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Convert a BigInt to a little-endian buffer.
|
|
108
|
+
* @param num The BigInt to convert.
|
|
109
|
+
* @param width The number of bytes that the resulting buffer should be.
|
|
110
|
+
* @returns A little-endian buffer representation of num.
|
|
111
|
+
*/
|
|
112
|
+
function toBufferLE(num, width) {
|
|
113
|
+
if (typeof window !== "undefined" || converter === undefined) {
|
|
114
|
+
const hex = num.toString(16);
|
|
115
|
+
const buffer = Buffer.from(hex.padStart(width * 2, "0").slice(0, width * 2), "hex");
|
|
116
|
+
buffer.reverse();
|
|
117
|
+
return buffer;
|
|
118
|
+
}
|
|
119
|
+
// Allocation is done here, since it is slower using napi in C
|
|
120
|
+
return converter.fromBigInt(num, Buffer.allocUnsafe(width), false);
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Convert a BigInt to a big-endian buffer.
|
|
124
|
+
* @param num The BigInt to convert.
|
|
125
|
+
* @param width The number of bytes that the resulting buffer should be.
|
|
126
|
+
* @returns A big-endian buffer representation of num.
|
|
127
|
+
*/
|
|
128
|
+
function toBufferBE(num, width) {
|
|
129
|
+
if (typeof window !== "undefined" || converter === undefined) {
|
|
130
|
+
const hex = num.toString(16);
|
|
131
|
+
return Buffer.from(hex.padStart(width * 2, "0").slice(0, width * 2), "hex");
|
|
132
|
+
}
|
|
133
|
+
return converter.fromBigInt(num, Buffer.allocUnsafe(width), true);
|
|
134
|
+
}
|
|
135
|
+
// ========== Conversion Utilities ==========
|
|
136
|
+
/**
|
|
137
|
+
* Convert a bigint to a Buffer with automatic sizing.
|
|
138
|
+
* Uses big-endian encoding and calculates the minimum buffer size needed.
|
|
139
|
+
* @param num The bigint to convert
|
|
140
|
+
* @returns A big-endian Buffer representation
|
|
141
|
+
*/
|
|
142
|
+
function bigintToBuf(num) {
|
|
143
|
+
if (num < BigInt(0)) {
|
|
144
|
+
throw new Error("bigintToBuf: negative bigint values are not supported");
|
|
145
|
+
}
|
|
146
|
+
if (num === BigInt(0)) {
|
|
147
|
+
return Buffer.from([0]);
|
|
148
|
+
}
|
|
149
|
+
// Calculate the number of bytes needed
|
|
150
|
+
const hex = num.toString(16);
|
|
151
|
+
const width = Math.ceil(hex.length / 2);
|
|
152
|
+
return toBufferBE(num, width);
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Convert a Buffer to a bigint.
|
|
156
|
+
* Assumes big-endian encoding.
|
|
157
|
+
* @param buf The buffer to convert
|
|
158
|
+
* @returns A bigint representation of the buffer
|
|
159
|
+
*/
|
|
160
|
+
function bufToBigint(buf) {
|
|
161
|
+
return toBigIntBE(buf);
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Convert a bigint to a hexadecimal string.
|
|
165
|
+
* @param num The bigint to convert
|
|
166
|
+
* @returns A hexadecimal string (without '0x' prefix)
|
|
167
|
+
*/
|
|
168
|
+
function bigintToHex(num) {
|
|
169
|
+
if (num < BigInt(0)) {
|
|
170
|
+
throw new Error("bigintToHex: negative bigint values are not supported");
|
|
171
|
+
}
|
|
172
|
+
const hex = num.toString(16);
|
|
173
|
+
// Ensure even length for proper byte representation
|
|
174
|
+
return hex.length % 2 === 0 ? hex : "0" + hex;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Convert a hexadecimal string to a bigint.
|
|
178
|
+
* @param hex The hexadecimal string (with or without '0x' prefix)
|
|
179
|
+
* @returns A bigint representation
|
|
180
|
+
*/
|
|
181
|
+
function hexToBigint(hex) {
|
|
182
|
+
// Remove '0x' prefix if present
|
|
183
|
+
const cleanHex = hex.startsWith("0x") ? hex.slice(2) : hex;
|
|
184
|
+
if (cleanHex.length === 0) {
|
|
185
|
+
return BigInt(0);
|
|
186
|
+
}
|
|
187
|
+
return BigInt(`0x${cleanHex}`);
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Convert a bigint to a decimal text string.
|
|
191
|
+
* @param num The bigint to convert
|
|
192
|
+
* @returns A decimal string representation
|
|
193
|
+
*/
|
|
194
|
+
function bigintToText(num) {
|
|
195
|
+
return num.toString(10);
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Convert a decimal text string to a bigint.
|
|
199
|
+
* @param text The decimal string to convert
|
|
200
|
+
* @returns A bigint representation
|
|
201
|
+
*/
|
|
202
|
+
function textToBigint(text) {
|
|
203
|
+
if (!text?.trim()) {
|
|
204
|
+
throw new Error("textToBigint: input string cannot be empty");
|
|
205
|
+
}
|
|
206
|
+
try {
|
|
207
|
+
return BigInt(text);
|
|
208
|
+
}
|
|
209
|
+
catch (e) {
|
|
210
|
+
throw new Error(`textToBigint: invalid decimal string "${text}" ${e instanceof Error ? e.message : String(e)}`);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Convert a bigint to a base64 string.
|
|
215
|
+
* @param num The bigint to convert
|
|
216
|
+
* @returns A base64 string representation
|
|
217
|
+
*/
|
|
218
|
+
function bigintToBase64(num) {
|
|
219
|
+
if (num < BigInt(0)) {
|
|
220
|
+
throw new Error("bigintToBase64: negative bigint values are not supported");
|
|
221
|
+
}
|
|
222
|
+
const buf = bigintToBuf(num);
|
|
223
|
+
return buf.toString("base64");
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Convert a base64 string to a bigint.
|
|
227
|
+
* @param base64 The base64 string to convert
|
|
228
|
+
* @returns A bigint representation
|
|
229
|
+
*/
|
|
230
|
+
function base64ToBigint(base64) {
|
|
231
|
+
if (!base64?.trim()) {
|
|
232
|
+
throw new Error("base64ToBigint: input string cannot be empty");
|
|
233
|
+
}
|
|
234
|
+
// Trim whitespace and validate base64 format (allows padding)
|
|
235
|
+
const cleaned = base64.trim();
|
|
236
|
+
if (!/^[A-Za-z0-9+/]+=*$/.test(cleaned)) {
|
|
237
|
+
throw new Error("base64ToBigint: invalid base64 string format");
|
|
238
|
+
}
|
|
239
|
+
const buf = Buffer.from(cleaned, "base64");
|
|
240
|
+
return bufToBigint(buf);
|
|
241
|
+
}
|
|
242
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,gCAWC;AAED,oDAOC;AAOD,gCASC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Ac,CAAC,GAAW;IACxC,IAAI,GAAG,GAAG,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;QACpB,MAAM,IAAI,KAAK,CAAC,0DAA0D,CAAC,CAAC;IAC9E,CAAC;IACD,MAAM,GAAG,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC;IAC7B,OAAO,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;AAChC,CAAC;AAED;;;;GAIG;AACH,SAAgB,cAAc,CAAC,MAAc;IAC3C,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE,CAAC;QACpB,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;IAClE,CAAC;IACD,8DAA8D;IAC9D,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,EAAE,CAAC;IAC9B,IAAI,CAAC,oBAAoB,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;QACxC,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;IAClE,CAAC;IACD,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IAC3C,OAAO,WAAW,CAAC,GAAG,CAAC,CAAC;AAC1B,CAAC"}
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("buffer"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("buffer"),B=require("path"),M=require("fs"),p=require("#pkg"),T=9,l="0x0",P=t=>t.startsWith("0x")||t.startsWith("0X")?t:`0x${t}`,d=t=>{if(t===0n)return l;const e=t<0n,n=e?-t:t,r=p.bigintToHex(n);return`${e?"-":""}0x${r}`},u=t=>{if(!t)return 0n;const e=t.trim();if(e.length===0)return 0n;const n=e.startsWith("-"),r=n?e.slice(1):e,i=P(r),g=p.hexToBigint(i);return n?-g:g};function H(t,e=T){if(!Number.isFinite(t))return l;const n=Math.pow(10,e),r=BigInt(Math.round(t*n));return d(r)}function V(t,e=T){const n=u(t);if(n===0n)return 0;const r=Math.pow(10,e);return Number(n)/r}function q(t,e){return d(u(t)+u(e))}function z(t,e){return d(u(t)-u(e))}function W(t){if(t.length===0)return l;const e=t.reduce((n,r)=>n+u(r),0n);return d(e/BigInt(t.length))}function j(t,e){const n=u(t)-u(e);return n===0n?0:n>0n?1:-1}function D(t){return u(t)}let b=!1,f,h;const a=typeof globalThis<"u"&&typeof globalThis.document<"u",v=[B.resolve(__dirname,".."),B.resolve(__dirname,"../../.."),B.resolve(__dirname,"../../../../")],X=()=>{for(const t of v){const e=B.join(t,"build","Release","bigint_buffer.node");if(M.existsSync(e))return t}return v[0]};function Z(){try{const t=require("bindings"),e=X();return t({bindings:"bigint_buffer",module_root:e})}catch(t){h=t;return}}a||(f=Z(),b=f!==void 0,!b&&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));f===void 0&&(f={toBigInt:(t,e=!0)=>{const n=o.Buffer.from(t);e||n.reverse();const r=n.toString("hex");return r.length===0?0n:BigInt(`0x${r}`)},fromBigInt:(t,e,n=!0)=>{const r=t.toString(16),i=e.length,g=r.padStart(i*2,"0").slice(0,i*2),m=o.Buffer.from(g,"hex");return n||m.reverse(),m.copy(e),e}});function w(t){if(a||f===void 0){const e=o.Buffer.from(t);e.reverse();const n=e.toString("hex");return n.length===0?BigInt(0):BigInt(`0x${n}`)}return f.toBigInt(t,!1)}function k(){try{return w(o.Buffer.from([1,0]))===BigInt(1)}catch{return!1}}function J(t){if(a||f===void 0){const e=t.toString("hex");return e.length===0?BigInt(0):BigInt(`0x${e}`)}return f.toBigInt(t,!0)}function C(t,e){if(a||f===void 0){const n=t.toString(16),r=o.Buffer.from(n.padStart(e*2,"0").slice(0,e*2),"hex");return r.reverse(),r}return f.fromBigInt(t,o.Buffer.allocUnsafe(e),!1)}function G(t,e){if(a||f===void 0){const n=t.toString(16);return o.Buffer.from(n.padStart(e*2,"0").slice(0,e*2),"hex")}return f.fromBigInt(t,o.Buffer.allocUnsafe(e),!0)}function c(t,e=!1,n){const r=t.match(/^(0x)?([\da-fA-F]+)$/);if(r==null)throw new RangeError("input must be a hexadecimal string, e.g. '0x124fe3a' or '0214f1b2'");let i=r[2];if(n!==void 0){if(n<i.length/2)throw new RangeError(`expected byte length ${n} < input hex byte length ${Math.ceil(i.length/2)}`);i=i.padStart(n*2,"0")}return e?"0x"+i:i}function E(t,e=!1){if(t<0)throw RangeError("a should be a non-negative integer. Negative values are not supported");return I(S(t),e)}function y(t){let e=8n;ArrayBuffer.isView(t)?e=BigInt(t.BYTES_PER_ELEMENT*8):t=new Uint8Array(t);let n=0n;for(const r of t.values()){const i=BigInt(r);n=(n<<e)+i}return n}function S(t,e=!1,n){if(t<0)throw RangeError("a should be a non-negative integer. Negative values are not supported");return c(t.toString(16),e,n)}function $(t){return BigInt(c(t,!0))}function Y(t){if(t<0)throw RangeError("a should be a non-negative integer. Negative values are not supported");return _(I(t.toString(16)))}function K(t){return $(N(A(t)))}function x(t){if(o.Buffer.isBuffer(t))return t;if(ArrayBuffer.isView(t))return o.Buffer.from(t.buffer,t.byteOffset,t.byteLength);if(t instanceof ArrayBuffer)return o.Buffer.from(new Uint8Array(t));throw new TypeError("Unsupported input type for Buffer.from")}function _(t){const e=x(t);return a?new TextDecoder().decode(new Uint8Array(e)):o.Buffer.from(e).toString()}function A(t,e=!1){return!a&&!e?o.Buffer.from(new TextEncoder().encode(t).buffer):new TextEncoder().encode(t).buffer}function N(t,e=!1,n){if(a){let r="";const i="0123456789abcdef";return ArrayBuffer.isView(t)?t=new Uint8Array(t.buffer.slice(t.byteOffset,t.byteOffset+t.byteLength)):t=new Uint8Array(t),t.forEach(g=>{r+=i[g>>4]+i[g&15]}),c(r,e,n)}else{const r=x(t);return ArrayBuffer.isView(r)&&(t=new Uint8Array(r.buffer.slice(r.byteOffset,r.byteOffset+r.byteLength))),c(o.Buffer.from(x(t)).toString("hex"),e,n)}}function I(t,e=!1){let n=c(t);if(n=c(t,!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 e?r.buffer.slice(r.byteOffset,r.byteOffset+r.byteLength):r}}function Q(t,e=!1,n=!0){if(t<0n)throw new RangeError("negative bigint");const r=E(t);let i=o.Buffer.isBuffer(r)?r.toString("base64"):o.Buffer.from(r).toString("base64");return e&&(i=i.replace(/\+/g,"-").replace(/\//g,"_")),n||(i=i.replace(/=+$/,"")),i}function tt(t){if(!t||t.trim()==="")return 0n;const e=t.trim();if(!/^[A-Za-z0-9+/=_-]*$/.test(e))throw new RangeError("invalid base64");let n=e.replace(/-/g,"+").replace(/_/g,"/");for(;n.length%4!==0;)n+="=";const r=o.Buffer.from(n,"base64");return y(r)}const et=Object.freeze(Object.defineProperty({__proto__:null,FIXED_POINT_DECIMALS:T,ZERO_FIXED_POINT:l,addFixedPoint:q,averageFixedPoint:W,base64ToBigint:tt,bigintToBase64:Q,bigintToBuf:E,bigintToHex:S,bigintToText:Y,bufToBigint:y,bufToHex:N,bufToText:_,compareFixedPoint:j,fixedPointToBigInt:D,fromFixedPoint:V,hexToBigint:$,hexToBuf:I,get isNative(){return b},parseHex:c,subtractFixedPoint:z,textToBigint:K,textToBuf:A,toBigIntBE:J,toBigIntLE:w,toBigIntValue:u,toBufferBE:G,toBufferLE:C,toFixedPoint:H,validateBigIntBuffer:k},Symbol.toStringTag,{value:"Module"}));let s;exports.isNative=!1;if(typeof window>"u")try{s=require("bindings")("bigint_buffer"),exports.isNative=s!==void 0}catch(t){console.warn("bigint: Failed to load bindings, pure JS will be used (try npm run rebuild?)",t)}function R(t){if(typeof window<"u"||s===void 0){const e=Buffer.from(t);e.reverse();const n=e.toString("hex");return n.length===0?BigInt(0):BigInt(`0x${n}`)}return s.toBigInt(t,!1)}function nt(){try{return R(Buffer.from([1,0]))===BigInt(1)}catch{return!1}}function F(t){if(typeof window<"u"||s===void 0){const e=t.toString("hex");return e.length===0?BigInt(0):BigInt(`0x${e}`)}return s.toBigInt(t,!0)}function rt(t,e){if(typeof window<"u"||s===void 0){const n=t.toString(16),r=Buffer.from(n.padStart(e*2,"0").slice(0,e*2),"hex");return r.reverse(),r}return s.fromBigInt(t,Buffer.allocUnsafe(e),!1)}function O(t,e){if(typeof window<"u"||s===void 0){const n=t.toString(16);return Buffer.from(n.padStart(e*2,"0").slice(0,e*2),"hex")}return s.fromBigInt(t,Buffer.allocUnsafe(e),!0)}function U(t){if(t<BigInt(0))throw new Error("bigintToBuf: negative bigint values are not supported");if(t===BigInt(0))return Buffer.from([0]);const e=t.toString(16),n=Math.ceil(e.length/2);return O(t,n)}function L(t){return F(t)}function it(t){if(t<BigInt(0))throw new Error("bigintToHex: negative bigint values are not supported");const e=t.toString(16);return e.length%2===0?e:"0"+e}function ot(t){const e=t.startsWith("0x")?t.slice(2):t;return e.length===0?BigInt(0):BigInt(`0x${e}`)}function ft(t){return t.toString(10)}function ut(t){if(!t?.trim())throw new Error("textToBigint: input string cannot be empty");try{return BigInt(t)}catch(e){throw new Error(`textToBigint: invalid decimal string "${t}" ${e instanceof Error?e.message:String(e)}`)}}function st(t){if(t<BigInt(0))throw new Error("bigintToBase64: negative bigint values are not supported");return U(t).toString("base64")}function at(t){if(!t?.trim())throw new Error("base64ToBigint: input string cannot be empty");const e=t.trim();if(!/^[A-Za-z0-9+/]+=*$/.test(e))throw new Error("base64ToBigint: invalid base64 string format");const n=Buffer.from(e,"base64");return L(n)}exports.base64ToBigint=at;exports.bigintToBase64=st;exports.bigintToBuf=U;exports.bigintToHex=it;exports.bigintToText=ft;exports.bufToBigint=L;exports.conversionUtils=et;exports.hexToBigint=ot;exports.textToBigint=ut;exports.toBigIntBE=F;exports.toBigIntLE=R;exports.toBufferBE=O;exports.toBufferLE=rt;exports.validateBigIntBuffer=nt;
|